Bash 你觉得美元怎么样?美元在Shell脚本中代表什么?
我有以下两段代码,我不太确定是什么$?和$#代表。请帮忙 代码一Bash 你觉得美元怎么样?美元在Shell脚本中代表什么?,bash,shell,posix,Bash,Shell,Posix,我有以下两段代码,我不太确定是什么$?和$#代表。请帮忙 代码一 #!/bin/bashUSERID="$1" /bin/id $USERID 2>/dev/null [ $? -eq 0 ] && echo "User found" || echo "User not found" /bin/id -g $USERID 2>/dev/null [ $? -eq 0 ] && echo "Group found" || echo "Group
#!/bin/bashUSERID="$1"
/bin/id $USERID 2>/dev/null
[ $? -eq 0 ] && echo "User found" || echo "User not found"
/bin/id -g $USERID 2>/dev/null
[ $? -eq 0 ] && echo "Group found" || echo "Group not found" `
$ cat > mtable
代码二
#!/bin/sh
#
#Script to test for loop
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo "Use to print multiplication table for given number"
exit 1
fi
n=$1
for i in 1 2 3 4 5 6 7 8 9 10
do
echo "$n * $i = `expr $i \* $n`"
done
谢谢请查看
bash
的手册页:
$#扩展为十进制位置参数的数量
美元?扩展到最近执行的前台管道的状态
$?
提供上一个执行命令的返回代码
$#
提供给脚本的命令行参数数量
因此,基本上,if条件检查给定的参数数量是否正确