Passing parameters from a shell script to a perl program does not save spaces

I have a perl script test.pl that reads arguments from the command line

#!/usr/bin/perl -w  
for( @ARGV ) { print( "$_\n" ) } ;

This works well when I pass parameters like "a b" "c d" e on the command line
Result:

a b
c d
e

If I declare a variable

X='"a b" "c d" e'

and then run

test.pl $X

I get

"a
b"
"c
d"
e

perl script , .
, .
, perl .
, perl script .
perl script ?

+4
3

@all . , , , , . , perl, . .

0

bash, , , test.pl:

declare -a X=("a b" "c d" e)
test.pl "${X[@]}"

, :

X=("a b")
X+=("c d")
X+=("e")
+2

.

./test.pl "$X"

.

/bin/bash -c "./test.pl $X"

Georg

+2

Source: https://habr.com/ru/post/1664295/


All Articles