Last active
July 1, 2016 01:41
-
-
Save yn-misaki/1ae7bb7a213123d8d857aafbae87db0e to your computer and use it in GitHub Desktop.
シェルスクリプトの1行目に書くおまじないで使える便利オプション集 ref: http://qiita.com/yn-misaki/items/6fcfab082dd664f10d4e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./test.sh | |
+ ONE=1 | |
+ TWO=2 | |
+ echo 'command: test 1 -eq 2' | |
command: test 1 -eq 2 | |
+ test 1 -eq 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ /tmp/test.sh | |
command: test 1 -eq 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -v | |
ONE=1 | |
TWO=2 | |
echo "command: test ${ONE} -eq ${TWO}" | |
command: test 1 -eq 2 | |
test ${ONE} -eq ${TWO} | |
echo status: $? | |
status: 1 | |
echo "command: test ${ONE} -eq ${ONE}" | |
command: test 1 -eq 1 | |
test ${ONE} -eq ${ONE} | |
echo status: $? | |
status: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ ONE=1 | |
+ TWO=2 | |
+ echo 'command: test 1 -eq 2' | |
command: test 1 -eq 2 | |
+ test 1 -eq 2 | |
+ echo status: 1 | |
status: 1 | |
+ echo 'command: test 1 -eq 1' | |
command: test 1 -eq 1 | |
+ test 1 -eq 1 | |
+ echo status: 0 | |
status: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ls -l /bin/sh | |
lrwxrwxrwx. 1 root root 4 6月 8 14:30 /bin/sh -> bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd /tmp | |
$ vim test.sh | |
=================== | |
#!/bin/sh | |
ONE=1 | |
TWO=2 | |
echo "command: test ${ONE} -eq ${TWO}" | |
test ${ONE} -eq ${TWO} | |
echo status: $? | |
echo "command: test ${ONE} -eq ${ONE}" | |
test ${ONE} -eq ${ONE} | |
echo status: $? | |
=================== | |
# 実行権限をつける | |
$ chmod +x test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./test.sh | |
command: test 1 -eq 2 | |
status: 1 ← 終了ステータス | |
command: test 1 -eq 1 | |
status: 0 ← 終了ステータス |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment