我正在更改一个结构如下的 bash 脚本:
#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
我应该怎么做才能避免$1
函数参数和set
命令中的其他值发生冲突?