【发布时间】:2019-05-19 23:39:35
【问题描述】:
我正在设置一个使用来自另一个脚本的变量的脚本。
脚本 1 有变量
脚本 2 获取脚本 1 并输出意外错误。
通过 GCP 安装全新的 Debian 9。
1.sh
1="test"
2="test2"
3="test3"
2.sh
source 1.sh
echo $1
echo $2
echo $3
运行 2.sh,我预计:
test
test2
test3
但我收到了:
1.sh: line 2: 1=test: command not found
1.sh: line 3: 2=test2: command not found
1.sh: line 4: 3=test3: command not found
#empty line#
#empty line#
#empty line#
This link 告诉我 bash 变量是这样声明的。
我该如何解决这个问题?
【问题讨论】:
-
但链接在于如何以这种方式分配变量名称。您是否曾经在 bash 中尝试过
1="test"manually ?您还将收到 command not found 错误。你不能像这样设置位置参数。