如何在bash变量中存储arg和引用的arg值?

时间:2012-09-04 02:46:57

标签: bash

假设我有两个脚本,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以将两个参数-ehello there传递给printargs.sh?即我想printargs.sh打印

1=-e
2=hello there
3=

我觉得这个问题多年来一直困扰着我!我能得到它的唯一方法是创建两个变量。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

The answer has been around for years.

args=(-e 'hello there')
./printargs.sh "${args[@]}"