how to include slashes "/" in @ARGV (Perl)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to include slashes "/" in @ARGV (Perl)
# 1  
Old 01-29-2006
how to include slashes "/" in @ARGV (Perl)

Hello
I have simple script that will accept as arg string like this :

".../foo/blah/,.../.../foo1/,.../blah"

now perl automatically removes the slashes "/" , I can't escape the slashes in the input I have to control on it
so how can I force perl to not touch this slashes?


Thanks
allot
# 2  
Old 01-30-2006
I haven't heard about Perl removing slashes from anything passed into @ARGV.

In particular, I performed this test (on a Windows machine right now, but I guess this is true for *nix as well):

Code:
D:\Documents and Settings\bernardchan>perl -e "print $ARGV[0]" "a/b/c/d"
a/b/c/d

Maybe the shell or some other intermediate programs are the culprit?
# 3  
Old 01-30-2006
let me show you what i mean

Hello i ahev this simple simple script that gets input and print input :
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl

$libs = @ARGV[0];
print "\n$libs \n";
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

im excutinng the script as this :

myscript.pl ..\blah,..\..\..\blahq,..\..\..\..\..\blah\blah\blah,..\..\..\..\..\blah11\bo,..\..\..\..\..\Librari es\Include\foo,..\..\..\..\..\foo\foo1\fo2\fo3,

and the print output is :

..blah,......blahq,..........blah\blah\blah,..........blah11bo,..........LibrariesIncludefoo,....... ...foofoo1fo2fo3,

as you see all the slashes are gone
how can i avoid this ?

thanks
# 4  
Old 01-30-2006
I knew what you meant. As I said, obviously it is the shell, not Perl, that is eating the backslashes.

Code:
cbkihong@cbkihong:~$ perl -e 'print $ARGV[0] . "\n"' '..\b\v\d'
..\b\v\d
cbkihong@cbkihong:~$ perl -e 'print $ARGV[0] . "\n"' ..\b\v\d
..bvd
cbkihong@cbkihong:~$ perl -e 'print $ARGV[0] . "\n"' ..\\b\\v\\d
..\b\v\d

If you feel more comfortable looking at your own example:

Quote:
cbkihong@cbkihong:~$ /dev/shm/test.pl ..\blah,..\..\..\blahq,..\..\..\..\..\blah\blah\blah,..\..\..\..\..\blah11\bo,..\..\..\..\..\Librari es\Include\foo,..\..\..\..\..\foo\foo1\fo2\fo3,

..blah,......blahq,..........blahblahblah,..........blah11bo,..........Librari
cbkihong@cbkihong:~$ /dev/shm/test.pl '..\blah,..\..\..\blahq,..\..\..\..\..\blah\blah\blah,..\..\..\..\..\blah11\bo,..\..\..\..\..\Librar i es\Include\foo,..\..\..\..\..\foo\foo1\fo2\fo3,'

..\blah,..\..\..\blahq,..\..\..\..\..\blah\blah\blah,..\..\..\..\..\blah11\bo,..\..\..\..\..\Librari es\Include\foo,..\..\..\..\..\foo\foo1\fo2\fo3,
Even though you said you cannot control the controlling process, but actually it is that process that has made an incorrect assumption that parameters need not be quoted, but the fact is special characters are treated specially by the shell.

For instance, the bash manpage has this:

Quote:
There are three quoting mechanisms: the escape character, single quotes, and double quotes.

A non-quoted backslash (\) is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>. If a \<newline> pair appears, and the backslash is not itself quoted, the \<newline> is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).

Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \, and, when history expansion is enabled, !. The characters $ and ` retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: $, `, " , \, or <newline>. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ! appearing in double quotes is escaped using a backslash. The backslash preceding the ! is not removed.
So you have no option but to teach the process that generates the command to quote the parameters or escape the offending characters (\ $ etc.), because the backslashes have already been gone by the time they reach Perl. Perl has no way of getting them back!
# 5  
Old 04-07-2009
ARGV how to enter "/db2qdir1/scripts/db2" as input

I want to execute a perl program that has an argument like this:
sys_db2actp_runstats_AUTOSYS.pl "/db2qdir1/scripts/db2" db2actq EMLNK_DB
in UNIX. It doesn't accept the /db2qdir1/scripts/db2 argument. I have tried enclosing with double quotes, single quotes, tick marks "`", and no quotes. What am I doing wrong ?
# 6  
Old 04-07-2009
Quote:
Originally Posted by jimpalla
What am I doing wrong ?
You're posting a new question onto the end of a 3 year old thread. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Emergency UNIX and Linux Support

Accidentally Changed File Ownership to Include a "Comment" [AIX]

Hi. I've had a little mishap. To cut a long story short, I've accidentally recursively ran chown on a directory (actually a bunch of 'em). Not a problem in itself, but I had a slight error in the code I used to get the list of directories and ended up with a comment in the file ownership. ... (15 Replies)
Discussion started by: Scott
15 Replies

4. Shell Programming and Scripting

AWK "make a new column that include increasing numbers"

please help!!!!!! I have a file .txt that has only one column like that: 34.1 35.5 35.6 45.6 ... Now, i want to add a column in the left in which the values of this column increase by 0.4 , for example: 0.0 34.1 0.4 35.5 0.8 35.6 1.2 45.6 How can i do with awk instructions??? ... (2 Replies)
Discussion started by: tienete
2 Replies

5. Shell Programming and Scripting

Need to include " , " between two parameter in perl

i have two files t4.txt para1 para2 t5.txt 34 56 after compiling the following in perl system("paste t4.txt t5.txt > table.txt"); i am getting o/p as para1 34 para2 56 but i need o/p as para1,34 para2,56 (3 Replies)
Discussion started by: roopa
3 Replies

6. Shell Programming and Scripting

mv command to include files beginning with "." (like .htaccess)

Hi, how can I get the mv command to include files beginning with . (such as .htaccess)? Right now when I mv a directory the .htaccess file is missing and I need to do this on a lot of directories, so there's a lot of wordpress permalinks that don't work anymore because the .htaccess file wasn't... (5 Replies)
Discussion started by: vanessafan99
5 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

Compare file names and select correct elements to include in "for each loop"

Hi everyone, I`ll try to be most clear I can explaining my help request. I have 2 folders Folder A-->This folder receives files through FTP constantly Folder B-->The files from Folder A are unzipped and then processed in Folder B Sometimes Folder A doesn`t contain all... (2 Replies)
Discussion started by: cgkmal
2 Replies

9. Shell Programming and Scripting

perl file, one line code include "length, rindex, substr", slow

Hi Everyone, # cat a.txt a;b;c;64O a;b;c;d;ee;f # cat a.pl #!/usr/bin/perl use strict; use warnings; my $tmp3 = ",,a,,b,,c,,d,,e,,f,,"; open(my $FA, "a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\;/, $_); if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Discussion started by: jimmy_y
3 Replies

10. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies
Login or Register to Ask a Question