passing string to ksh with system command

J

joez3

Hi all,
I have a perl scirpt that needs to pass some data to a ksh script, but
my problem is that one of the strings that I need to pass has a space
in it. So my ksh script thinks that this is 2 different strings. This
is how I have this coded right now:
$type = "com+ app";
system "runshell.ksh ".$item." "$type;

When the runshell.ksh run it looks like it only sees the com+ and not
the 2nd half of the string. Is there a way to encase my type string in
"". I have already tried using "/"com+ app/"" that that didn't seam to
help.
Thanks,
Zim
 
P

Paul Lalli

Hi all,
I have a perl scirpt that needs to pass some data to a ksh script, but
my problem is that one of the strings that I need to pass has a space
in it. So my ksh script thinks that this is 2 different strings. This
is how I have this coded right now:
$type = "com+ app";
system "runshell.ksh ".$item." "$type;

When the runshell.ksh run it looks like it only sees the com+ and not
the 2nd half of the string. Is there a way to encase my type string in
"". I have already tried using "/"com+ app/"" that that didn't seam to
help.

You escape quotes with a backslash, not a forward slash:

$type = "\"com+ app\"";

However, this is ugly. You have no reason for the perl string itself to
be enclosed in double quotes. Use single quotes:

$type = '"com+ app"';

Paul Lalli
 
M

Matthew Braid

Hi all,
I have a perl scirpt that needs to pass some data to a ksh script, but
my problem is that one of the strings that I need to pass has a space
in it. So my ksh script thinks that this is 2 different strings. This
is how I have this coded right now:
$type = "com+ app";
system "runshell.ksh ".$item." "$type;

When the runshell.ksh run it looks like it only sees the com+ and not
the 2nd half of the string. Is there a way to encase my type string in
"". I have already tried using "/"com+ app/"" that that didn't seam to
help.
Thanks,
Zim

If you're not using any shell meta characters (eg &, *, ? etc), you can
use the multi-argument form of system:

system('runshell.ksh', $item, $type);

This spawns runshell.ksh with arguments that _exactly match what you set
them to_. No shell gets in the way to process the arguments.

Of course if you _need_ to use shell metacharacters, you can't do it
this way - you'll need to quote the space yourself. You can either do it
like so:

$type = 'com+\ app'; # May not work in some shells
system("runshell.ksh $item $type");

or

$type = '"com+ app"';
system("runshell.ksh $item $type");

MB
 
M

Matthew Braid

Matthew said:
If you're not using any shell meta characters (eg &, *, ? etc), you can
use the multi-argument form of system:

system('runshell.ksh', $item, $type);

This spawns runshell.ksh with arguments that _exactly match what you set
them to_. No shell gets in the way to process the arguments.

Of course if you _need_ to use shell metacharacters, you can't do it
this way - you'll need to quote the space yourself. You can either do it
like so:

$type = 'com+\ app'; # May not work in some shells
system("runshell.ksh $item $type");

or

$type = '"com+ app"';
system("runshell.ksh $item $type");

MB

Just to be clear - by 'need to use shell metacharacters' I meant 'need
the shell to interpret shell metacharacters'. You can still use say:

system('grep', 'foo', 'a.*');

but it will try to grep for foo in a file literally named a.* - it won't
find all files starting with 'a.'

MB
 
T

Tad McClellan

This
is how I have this coded right now:
$type = "com+ app";
system "runshell.ksh ".$item." "$type;
^^^^
^^^^

Please have the courtesy to post Real Perl Code.

Is there a way to encase my type string in
"".


Yes. See the "Quote and Quote-like Operators" section in

perldoc perlop

for many different ways of quoting your strings, for example:

$type = "\"com+ app\"";

or

$type = qq("com+ app");

or use single quotes for ksh

$type = "'com+ app'";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top