假设我有两个脚本,printargs.sh:
#!/bin/bash
echo 1=$1
echo 2=$2
echo 3=$3
和passargs.sh:
#!/bin/bash
arg1="-e \"hello there\""
./printargs.sh $arg1
如何修改passargs.sh以将两个参数-e
和hello there
传递给printargs.sh?即我想printargs.sh打印
1=-e
2=hello there
3=
我觉得这个问题多年来一直困扰着我!我能得到它的唯一方法是创建两个变量。任何帮助将不胜感激。
答案 0 :(得分:1)
The answer has been around for years.
args=(-e 'hello there')
./printargs.sh "${args[@]}"