argument parser strips out " in arguments

argument parser strips out " in arguments

Post by Samant » Sat, 06 Mar 2004 14:19:59



Hi,

I would like to know how I can pass double quotes to a perl script in
a csh or sh in UNIX. ie
I have a test script which has:
#!/usr/local/bin/perl5
print "arg0\n";

print "\narg1\n";

print "\narg2\n";

print "\n";

and I say:
./test  hello  "1 2"
arg0
hello
arg1
1 2
arg2

I would like arg1 to be "1 2" and not just 1 2
It looks like the " are being stripped out of the argument by the
parser. Similarly, I would like:
./test  hello  '1 2'
arg0
hello
arg1
1 2
arg2

to print '1 2' for arg1.

the reason I need this is because I am passing "1 2" to another script
which requires these arguments to have "" around them. If the " is
missing, it only reads 1 instead of 1 2
IT is transparent to the user that this is a wrapper they are
executing and so I wnt to avoid doing things like \"1 2\" when passing
arguments.

Thanks in advance for any help,

Sam

 
 
 

argument parser strips out " in arguments

Post by j.. » Sat, 06 Mar 2004 15:19:56



> I would like to know how I can pass double quotes to a perl script in
> a csh or sh in UNIX. ie
> I have a test script which has:
> #!/usr/local/bin/perl5
> print "arg0\n";

> print "\narg1\n";

> print "\narg2\n";

> print "\n";

These are syntax errors. The first argument is $ARGV[0]. It's a good
idea to always

use warnings;
use strict;

in perl scripts (although that's not your problem here).

Quote:> and I say:
> ./test  hello  "1 2"
> arg0
> hello
> arg1
> 1 2
> arg2

> I would like arg1 to be "1 2" and not just 1 2

> It looks like the " are being stripped out of the argument by the
> parser.

Well, they're being stripped off by the shell. If you want quotes
around stuff that you emit from the perl script, you'll have to either
know what needs to be quoted, and add the quotes before you emit the
output, or quote everything when you output it. The latter is no doubt
easier, and won't bother the downstream script.

Joe
--
Everyone in this room is wearing a uniform, and don't kid yourself.
   - Frank Zappa

 
 
 

1. Local forwarding with "iptables" gives "invalid arguments"

Dear all,

while trying to set up a reverse proxy I ran into serious trouble with
iptables.

I'm trying to forward locally generated traffic to a remote machine.
But a command like

# iptables -A OUTPUT -t nat -p tcp -d 192.168.1.154 -j DNAT
--to-destination 192.168.1.250

fails with the laconic message "iptables: Invalid argument" which is
not helpful in any way.

I' running SuSE Linux Enterprise Server (last try was with their kernel
2.6.5-7.191-default)
and, YES, I have already rebuilt the kernel after setting
CONFIG_IP_NF_NAT_LOCAL=y.

Actually I built several kernel by now, the last one with all netfilter
stuff compiled in (not as modules).

However, the result stays the same whatever I try, that damn "Invalid
argument".

How can I find out what is the reason for that, how can I debug this
kind of stuff in a way that enables me to find what "argument" is
"invalid" here for what reason.

Benno

2. kermit and zmodem (rz and sz) for Solaris 2

3. script questions - passing argument as argument to another program

4. Ahhhhhh, that's it.

5. newbie: (command and its arguments) as a sh script argument

6. SCO emulation mode???

7. Taking arguments from pipe 'plus' one more argument

8. Install Oracle 8.1.6.1.0 on SuSE6.4

9. pushd <no arguments> versus cd <no arguments>

10. The argument to end all pro-Linux arguments

11. Disable interpreting/stripping of quotes for command-line arguments?

12. strip - or + from 1st argument

13. Adding LINUX to OS/2 system: "mount error, wrong argument"