Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quotes

Status
Not open for further replies.

TheDugsBaws

Technical User
Oct 23, 2007
114
EU
Hi all. I have a newb question about quoting.

I have a script that executes the following:

$grepcmd = "/bin/grep ";

$listserv is a list of servers

$details is the type of OS

The following line calls each:
my $list = `$grepcmd $listserv $details`;

My problem is that a few of the servers have a strange character in the name e.g. server 1 (houston).

It seems to be having trouble with the space or the bracket but the grep doesn't work for these clients.

How can I amend this in the script? Would double quotes around $listserv work?
 
The backticks will take whatever is in those three variables and run it as if on the command line of your operating system (which is presumably some flavour of Unix). If the command you produce isn't valid unix syntax, it won't work.

But what is the above intended to do? Is it really necessary to go out to grep, when Perl has powerful string handling functions of its own?

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Hi Chris,

It's intended to take in a list of servers i.e.

/bin/grep server 1 /usr
/bin/grep server 2 /var
/bin/grep server 1 (houston) /tmp

The problem is the "server1 (houston)" seems to be causing it problems
 
It's intended to take in a list of servers
But why? What are you trying to do with that list of servers once you've got it? Going out to grep may not be the best way of doing whatever-it-is.

And how do you expect this:
Code:
my $list = `$grepcmd $listserv $details`;
to be magically translated into this?:
Code:
/bin/grep server 1 /usr
/bin/grep server 2 /var
/bin/grep server 1 (houston) /tmp


-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Hey I got it working in the end. this is exactly what it does:

/bin/grep server 1 /usr
/bin/grep server 2 /var
/bin/grep server 1 (houston) /tmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top