当前位置: 技术问答>linux和unix
菜鸟求教,在线等待:case语句后报双分号错误
来源: 互联网 发布时间:2016-11-26
本文导语: i=0 comvar=(c,m,l,w,L) len=$(#array[*]) while [ $i -lt $len ]; do case "${comvar[$i]}" in "c") echo "bytes: " wc -c program1.sh;; "m") echo "chars: " wc -m program1.sh;; "l") echo "lines: " wc -l program1.sh;; "w") echo "words:...
i=0
comvar=(c,m,l,w,L)
len=$(#array[*])
while [ $i -lt $len ]; do
case "${comvar[$i]}" in
"c") echo "bytes: "
wc -c program1.sh;;
"m") echo "chars: "
wc -m program1.sh;;
"l") echo "lines: "
wc -l program1.sh;;
"w") echo "words: "
wc -w program1.sh;;
"L") echo "max-line-length: "
wc -L program1.sh;;
esac
let i+=1
done
程序老是报错说里面的;;错误。
comvar=(c,m,l,w,L)
len=$(#array[*])
while [ $i -lt $len ]; do
case "${comvar[$i]}" in
"c") echo "bytes: "
wc -c program1.sh;;
"m") echo "chars: "
wc -m program1.sh;;
"l") echo "lines: "
wc -l program1.sh;;
"w") echo "words: "
wc -w program1.sh;;
"L") echo "max-line-length: "
wc -L program1.sh;;
esac
let i+=1
done
程序老是报错说里面的;;错误。
|
做了一下修改,去掉""
#!/bin/bash
#jernymy case array test
i=0
comvar=(c m l w L)
#len=(#array[*]) #jernymy
len=${#comvar[*]} #jernymy array length use
echo "len=" $len
while [ $i -lt $len ]; do
case ${comvar[$i]} in
c) echo "bytes: "
wc -c program1.sh
;;
m) echo "chars: "
wc -m program1.sh
;;
l) echo "lines: "
wc -l program1.sh
;;
w) echo "words: "
wc -w program1.sh
;;
L) echo "max-line-length: "
wc -L program1.sh
;;
*) echo "default"
;;
esac
let i+=1
done
root@suker-desktop:/mnt/jernymy# ./program1.sh
len= 5
bytes:
592 program1.sh
chars:
592 program1.sh
lines:
33 program1.sh
words:
79 program1.sh
max-line-length:
43 program1.sh
root@suker-desktop:/mnt/jernymy#