# Function: wait until ifindex ok wait_ifindex() { whiletrue; do if [ -e /sys/class/net/$1/ifindex ]; then IFINDEX=$(cat /sys/class/net/$1/ifindex) echo"Get interface ${1} ifindex ${IFINDEX}" if [ "$IFINDEX"x != "0"x ]; then break; fi fi echo"Wait for interface ${1} ifindex OK for 1 second..." sleep 1 done }
wait_ifindex eth0
输出:
1 2
~$ ./test.sh Get interface eth0 ifindex 2
返回值
$# 返回上一个命令的执行结果。
1 2 3 4 5 6
~$ ls / bin dev initrd.img lib64 mnt root snap sys var boot etc initrd.img.old lost+found opt run sonic tmp vmlinuz cdrom home libmediaprocsbinsrvusrvmlinuz.old ~$ echo $# 0