実現したいこと
Linuxのシェルスクリプトを正しく動くようにしたい
発生している問題・分からないこと
引数の先頭文字が小文字なら
the '引数文字列' is lower case.
引数の先頭文字が大文字なら
the '引数文字列' is upper case.
と表示されるはずが、引数の先頭の文字が大文字でも「lower case」のほうが出力される
エラーメッセージ
error
1[root@localhost bashTest]# bash -x case.bash A 2+ case "$1" in 3+ echo 'the '\''A'\'' is lower case.' 4the 'A' is lower case. 5[root@localhost bashTest]# bash -x case.bash a 6+ case "$1" in 7+ echo 'the '\''a'\'' is lower case.' 8the 'a' is lower case. 9[root@localhost bashTest]# bash -x case.bash @ 10+ case "$1" in 11+ echo 'the '\''@'\'' is not alphabet' 12the '@' is not alphabet 13[root@localhost bashTest]#
該当のソースコード
bash
1 1 2 2 case "$1" in 3 3 [a-z]*) 4 4 echo "the '$1' is lower case." 5 5 ;; 6 6 [A-Z]*) 7 7 echo "the '$1' is upper case." 8 8 ;; 9 9 *) 10 10 echo "the '$1' is not alphabet" 11 11 ;; 12 12 esac
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
bash -x case.bash A
と
sh -x case.bash A
を試したが両方とも「lower case」のほうが出力された
補足
centOS7
###追記
カレントディレクトリで「ls -la」「cat case.bash」「bash case.bash AA」を実行した結果です。確実にカレントディレクトリのスクリプトファイルの「case.bash」を実行しているように見えます。
[root@localhost bashTest]# ls -la
total 28
drwxrwxr-x 2 tada tada 121 Feb 28 18:38 .
drwxrwxr-x 4 tada tada 86 Feb 28 16:59 ..
-rw-rw-r-- 1 tada tada 41 Feb 28 17:17 args.bash
-rw-rw-r-- 1 tada tada 156 Feb 28 18:13 case.bash
-rw-rw-r-- 1 tada tada 46 Feb 28 18:21 for.bash
-rw-rw-r-- 1 tada tada 62 Feb 28 18:38 function.bash
-rwxrwxr-x 1 tada tada 44 Feb 28 17:00 hello.bash
-rw-rw-r-- 1 tada tada 168 Feb 28 17:37 if.bash
-rw-rw-r-- 1 tada tada 72 Feb 28 18:26 while.bash
[root@localhost bashTest]# cat case.bash
case "$1" in
[a-z])
echo "the '$1' is lower case."
;;
[A-Z])
echo "the '$1' is upper case."
;;
*)
echo "the '$1' is not alphabet"
;;
esac
[root@localhost bashTest]# bash case.bash AA
the 'AA' is lower case.
[root@localhost bashTest]#
回答1件
あなたの回答
tips
プレビュー