我现在有一个bash脚本中,我已经硬编码的某些变量,而我希望能够通过传递参数来设置这些变量。传递变量bash脚本使用默认值
一个简单的例子:认为剧本example.sh
在那里我有硬编码值的变量data_names
和run_this
#!/bin/bash
data_names=("apple_picking" "iris")
run_this="TRUE"
#remainder of script runs things using these hard coded variables
我想知道是否可以编辑这个脚本,以便:
我可以通过传递参数来设置
data_names
和run_this
的值当我运行时bash example.sh
如果没有参数传递的任何
data_names
和run_this
到脚本,则变量应采取默认(硬编码)的值。
是的,这是可能的。你到目前为止尝试过什么,发生了什么? – Robert 2014-12-10 22:14:53