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

前端 未结 5 1389
孤街浪徒
孤街浪徒 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:27

    This is almost certainly a problem in the way you are reading the variable in your program.
    For instance suppose this is your script (just one line for testing):

    echo "$1"
    

    Let's call it echo.sh. If you run echo.sh "test best", you will get test best.

    But if your program says

    echo $1
    

    you might get behaviour like what you're seeing.

提交回复
热议问题