我改变它的结构如图这样的bash脚本:坐落在bash脚本VS功能参数
#somewhere in the code
sim_counts=#... some value
function_name()
{
set $sim_counts
for hostname in $linux_hostnames; do
if [ $1 -eq 0 ]; then # if sim_counts equal 0
shift # jump forward in sim_counts
continue
fi
# ... more code
shift
done
}
然后它被调用的脚本:
function_name
我想给这个功能介绍一个参数:
#somewhere in the code
sim_counts=#... some value
function_name()
{
ip=$1
set $sim_counts
for hostname in $linux_hostnames; do
if [ $1 -eq 0 ]; then # if sim_counts equal 0
shift # jump forward in sim_counts
continue
fi
# ... more code
shift
done
}
并调用方式如下功能:
function_name 10.255.192.123
我应该怎么做,以避免功能参数和set
命令其他价值的$1
冲突?
'$ sim_counts'代表什么? – 2013-02-08 14:56:22
@JonahBishop这是在特定机器上启动的进程值。 – Patryk 2013-02-08 15:02:40
由于您在调用'set'之前将函数的参数保存为'ip',我不确定是否存在真正的冲突。那就是说,为什么你需要在这里使用'set'?难道你不能像'$ 1'那样使用'sim_counts'吗? – chepner 2013-02-08 15:04:36