首页 > 解决方案 > Bash执行存储在变量中的多个命令而没有eval

问题描述

我有一个脚本wrapper.sh,它需要一个字符串作为参数。

包装器.sh

#!/usr/bin/env bash
node ./index.js $1

现在,如果我传递参数,因为hello它运行良好,但如果我传递hello&pwd,那么它将完整字符串作为参数传递给 nodejs 文件,而不是仅在 nodejs 中传递 hello 并单独运行 pwd。

例子

./wrapper.sh "hello"
# nodejs gets argument hello : Expected


./wrapper.sh "hello&pwd"
# nodejs gets argument hello&pwd : Not Expected
# Requied only hello in nodejs while pwd running separately 

我在网上尝试了很多解决方案,但似乎没有一个有效,除了evalbash -c不想使用的,因为脚本不会等待这些命令完成。

编辑

wrapper.sh由第三方软件执行,脚本的内容是由用户动态配置的,所以我手里没有什么。我的模块的工作是正确设置由第三方软件执行的脚本。

标签: bashshelleval

解决方案


推荐阅读