gpt4 book ai didi

linux - 从另一个脚本调用一个 shell 脚本并将该脚本的输出存储在一个变量中

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:19:24 26 4
gpt4 key购买 nike

我有 shell script1 1.sh。我有另一个 shell 脚本 2.sh,我需要在其中使用第一个脚本的功能并将其存储在一个变量中以在第二个脚本中使用。

这些似乎都不起作用:

a=$(sh 1.sh)
a=sh 1.sh
a=`sh 1.sh`

最佳答案

第一种方案是正确的,尝试举例:

echo 'echo "hello, world"' > echohello.sh
hello=$(sh echohello.sh)
echo $hello

也许你在 1.sh 中有错误或者它在不同的目录中?可以直接运行./1.sh调用吗?

关于linux - 从另一个脚本调用一个 shell 脚本并将该脚本的输出存储在一个变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45732824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com