By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,841 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,841 IT Pros & Developers. It's quick & easy.

perl with shell dont accept variable

P: 3
Hi

I am using running one perl command using shell scripts, but it won’t take variable
Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. ar="/usr/local/apache/conf"
  3. perl -00ne '/$1/ && print $_' $ar/httpd.conf  > domstat.txt
I am passing following things on command line
./domcheck.sh domainname.com
but perl unable to understand $1 even its not highlight as variable.
Mar 27 '08 #1
Share this Question
Share on Google+
5 Replies


KevinADC
Expert 2.5K+
P: 4,059
Hi

I am using running one perl command using shell scripts, but it won’t take variable
Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. ar="/usr/local/apache/conf"
  3. perl -00ne '/$1/ && print $_' $ar/httpd.conf  > domstat.txt
I am passing following things on command line
./domcheck.sh domainname.com
but perl unable to understand $1 even its not highlight as variable.
Where does $1 get defined?
Mar 28 '08 #2

P: 3
HI,


$1 = command line variable
it means i am passing

./domcheck.sh domainname.com

$1 = domainname.com
Mar 29 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
I think you may need to ask on a shell scripting forum, I do not have enough sh experience to know what the problem is. $1 is also a variable used by perl internally, but I am not sure if that would be a problem. Try this and see what happens:

Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. perl -e ' print $1;'
just pass your shell script a simple string and see if it gets printed by perl. If not then I think there is a conflict in trying to use the special variable $1 for this purpose.
Mar 29 '08 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
I think you may need to ask on a shell scripting forum, I do not have enough sh experience to know what the problem is. $1 is also a variable used by perl internally, but I am not sure if that would be a problem. Try this and see what happens:

Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. perl -e ' print $1;'
just pass your shell script a simple string and see if it gets printed by perl. If not then I think there is a conflict in trying to use the special variable $1 for this purpose.
I have to agree with Kevin. Run his test above and see if it works. My first feeling is that it might cause an issue with Perl as it has a $1 as well, but if his test works, it should work then.

Regards,

Jeff
Mar 29 '08 #5

P: 3
Hi,


Thankx for the help but i found another way to solve my problem.
Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2.  
  3. echo "perl -00ne '/$1/ && print \$_' $ar/httpd.conf.bak27marn" > vl.sh
  4. /bin/sh vl.sh
it is working fine.
as perl and shell both are differnt language they do understand different syntax so it would be good to redirect result in one file and run as perl.

Thank you
Mar 31 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.