Skip to content

Instantly share code, notes, and snippets.

@yn-misaki
Last active July 1, 2016 01:41
Show Gist options
  • Save yn-misaki/1ae7bb7a213123d8d857aafbae87db0e to your computer and use it in GitHub Desktop.
Save yn-misaki/1ae7bb7a213123d8d857aafbae87db0e to your computer and use it in GitHub Desktop.
シェルスクリプトの1行目に書くおまじないで使える便利オプション集 ref: http://qiita.com/yn-misaki/items/6fcfab082dd664f10d4e
$ ./test.sh
+ ONE=1
+ TWO=2
+ echo 'command: test 1 -eq 2'
command: test 1 -eq 2
+ test 1 -eq 2
$ /tmp/test.sh
command: test 1 -eq 2
#!/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
+ 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
$ ls -l /bin/sh
lrwxrwxrwx. 1 root root 4 6月 8 14:30 /bin/sh -> bash
$ 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
$ ./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