小编bbo*_*boy的帖子

参数编号变量不计算输入的参数

我有以下脚本:

echo  'Please select type file , the name of the input file and the name of the output file:

     a.plain ( please press a ) <input_file> <output_file>;
     b.complex ( please press b ) <input_file> <output_file>;'

read one two three
echo $#

if  [ $# -ne 3 ]; then
   echo "Insufficient arguments !"
   exit 1;
else
   echo "Number of passed parameters is ok"
fi
Run Code Online (Sandbox Code Playgroud)

$# 始终输出 0 ,当我稍后在脚本中使用 $one 、 $two 和 $three 时, read 命令会提供正确的变量

谢谢你。

bash shell-script

3
推荐指数
1
解决办法
1019
查看次数

标签 统计

bash ×1

shell-script ×1