如何找到传递给Bash脚本的参数数?
这就是我目前的情况:
#!/bin/bash
i=0
for var in "$@"
do
i=i+1
done
还有其他(更好的)方法来做这件事吗?
发布于 2018-03-23 13:13:15
参数的数目是$#
发布于 2018-03-23 14:21:31
#!/bin/bash
echo "The number of arguments is: $#"
a=${@}
echo "The total length of all arguments is: ${#a}: "
count=0
for var in "$@"
do
echo "The length of argument '$var' is: ${#var}"
(( count++ ))
(( accum += ${#var} ))
done
echo "The counted number of arguments is: $count"
echo "The accumulated length of all arguments is: $accum"
https://stackoverflow.com/questions/-100003671
复制相似问题