bash - 如何让 bash 脚本接受来自另一个脚本的变量,或者如果它没有接收到以默认值运行的变量?
问题描述
我正在尝试编辑我的脚本,以便不仅在直接运行时工作,为变量设置任何值,它还可以通过另一个脚本运行,该脚本向用户询问这些变量是什么。
我不能将这一切合二为一的原因是,有时我需要在我的大学集群上运行,而在这种情况下我无法读取变量。
这是主脚本中的相关代码:
#!/bin/bash
if [$# -eq 0]; then
echo "No input provided from control file, running with nwmag_looper values"
csv_name="testbatch_1510_Chkd"
Process="bq_tqhi_1510"
Higgs="tot"
basefilepath="/scratch/cb27g11/mg_run_basic/nw_mg_run.txt"
testfilepath="/scratch/cb27g11/mg_run_iridis/nwmag_runcard.txt"
elif [$# -eq 5]; then
echo "Input provided from control file, running with these values"
csv_name=$1
Process=$2
Higgs=$3
basefilepath=$4
testfilepath=$5
else
echo "Please provide exactly 5 inputs, csv_name, process name, higgs combination, filepath to basic MG runcard and filepath to functional MG runcard; or run directly from nwmag_looper.sh"
break
fi
到目前为止,我一直在尝试直接运行它,bash nwmag_looper.sh
但没有成功。在我进行更改以尝试使其双向运行之前,它运行良好,因此我认为在此代码段之外没有任何问题。
我收到这个错误
(base) [cb27g11@green0591 Looping_Bash]$ bash nwmag_looper.sh
nwmag_looper.sh: line 3: [0: command not found
nwmag_looper.sh: line 13: [0: command not found
Please provide exactly 5 inputs, csv_name, process name, higgs combination, filepath to basic MG runcard and filepath to functional MG runcard; or run directly from nwmag_looper.sh
nwmag_looper.sh: line 25: break: only meaningful in a `for', `while', or `until' loop
cut: /scratch/cb27g11/Looping_Bash/.csv: No such file or directory
data_coallator starting...
store_path is currently: /scratch/cb27g11/Data_Ripper_files/
Traceback (most recent call last):
File "/scratch/cb27g11/Data_Ripper_iridis/Data_coallator.py", line 17, in <module>
process = str(sys.argv[2])
IndexError: list index out of range
语法有问题吗?
解决方案
推荐阅读
- python - 我想从数据框中的行创建一个值列表,并删除前 2 个元素
- c# - 如何远程调试dll
- python-3.x - 按空格分割并添加值 - Python
- java - 如何在 JasperReport 中的 barChart 中的条形上方垂直旋转 itemLabels
- php - 使用流明文档中的示例代码时未定义的变量 $router
- react-native - 反应本机推送通知 onNotification 事件不起作用
- sapui5 - SAPUI5 无法获取表格可编辑单元格值
- ios - 仅从日期时间/日期选择器中快速按日期过滤
- python - Python:在(散点图)图中突出显示、标记或指示点
- sql-server - SSIS 动态文件名保存以备后用