-1
我想运行一个Shell脚本,但遇到了问题。我想运行某些代码集,当我提供参数和剩余应该运行,如果我不通过任何参数。 我想与ARGS运行部分:在Linux中没有命令行参数的情况下运行Shell脚本
#!/bin/bash
while [[ "$1" != "" ]]; do
case "$1" in
-c) cat /proc/cpuinfo | grep cores
;;
-d) fdisk -l | grep Disk | awk '{print $1,$2,$3,$4}' #fdisk -l 2> /dev/null | grep Disk | grep -v identifier
;;
esac
shift
done
,这部分没有任何ARGS
while [[ $# -eq 0 ]]; do
echo PART 2 $#
cat /proc/cpuinfo | grep cores
fdisk -l | grep Disk | awk '{print $1,$2,$3,$4}' #fdisk -l 2> /dev/null | grep Disk | grep -v identifier
break
done
我相信问题是与循环条件,但我不能明白什么?
感谢您的回复......您能解释为什么我的逻辑失败了吗? – Ismail
假设发布的代码是完整的脚本,那么明显在第一部分'##'后总是为零,或者是因为它从一开始就是零,或者因为你有'shift'所有参数,所以第二部分无条件运行。 – AlexP
感谢您的解释。 – Ismail