在Bash脚本Linux

时间:2016-10-05 22:51:28

标签: linux bash scripting

这个脚本应该查看我的参数并告诉我这个单词是以大写,小写还是数字开头。现在,当我输入一个单词时,它告诉我它们都是大写的。谢谢。

#!/bin/bash

startwithdigit=0
startwithupper=0
startwithlower=0
startwithother=0

for digit in $@

do
case $@ in

    [[:lower:]]* ) startwithlower=$((startwithlower+1)) ;;

    [[:upper:]]* ) startwithupper=$((startwithupper+1)) ;;

    [[:digit:]]* ) startwithdigit=$((startwithdigit+1)) ;;

esac

done

echo $startwithlower words begin with a lowercase
echo $startwithupper words begin with a capital
echo $startwithdigit words begin with a digit

〜 〜

1 个答案:

答案 0 :(得分:1)

请尝试以下方法:

我正在使用if语句而不是case,并且我计算通过附加到文件中并稍后进行字数统计,而不是每次向计数器添加1。

<!DOCTYPE html>
<html>
<body>

<p><a href="https://www.youtube.com/embed/ALqFFeU-Wp8">Full Screen</a></p>

</body>
</html>

#剧本。

# Sample data

"India China dubai germany 123 456 666" to the script. 

 It has 2 uppercase words, 2 lowercase words and 3 digit words.

# Sample output

bash$> ./upper_lower.sh "India China dubai germany 123 456 666"

2 words are lowercase

2 words are uppercase

3 words are digits