Bash: pass variable as a single parameter / shell quote parameter

前端 未结 5 1386
孤街浪徒
孤街浪徒 2021-01-23 02:32

I\'m writing a bash script which has to pass a variable to another program:

./program $variable

The problem is, it is absolutely necessary for

5条回答
  •  走了就别回头了
    2021-01-23 03:17

    did you try with var="hello world"?

    i tried this in my solaris box.

    > setenv var "hello world"
    > cat temp.sh
    #!/bin/sh
    
    echo $1
    echo $2
    > ./temp.sh "$var"
    hello world
    
    >
    

    as you can see the $2 is not printed.$var is considered as only one argument.

提交回复
热议问题