bash - 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
我在网上尝试了很多解决方案,但似乎没有一个有效,除了eval
我bash -c
不想使用的,因为脚本不会等待这些命令完成。
编辑
wrapper.sh
由第三方软件执行,脚本的内容是由用户动态配置的,所以我手里没有什么。我的模块的工作是正确设置由第三方软件执行的脚本。
解决方案
推荐阅读
- javascript - 删除父 div 留下其子 div
- python - 如何将新词分类成亲和传播簇?
- vue.js - 如何使用 Vue.js 和 Nuxt 保护数据?
- google-sheets - Google Query Language 将不会显示位于单元格中提供的两个日期之间的范围
- r - 如何更改列表中数据框的列名
- php - Symfony - 在控制器中使用发布数据重定向
- javascript - 带有非拉丁字体的 jsPDF
- android - RecyclerView/Adapter 中的 TimePicker 使屏幕变暗
- bash - Bash:如果字符不存在,如何在行尾添加字符?
- sql - 根据季度查找所有记录