「ShellScript」終了ステータスの値を取得する方法

2021年4月22日

書式
$?
成功:0
失敗:1
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/bash
read x
read y
(( $x == $y ));
echo "終了ステータスの値: "$?
#!/bin/bash read x read y (( $x == $y )); echo "終了ステータスの値: "$?
#!/bin/bash
read x
read y
(( $x == $y ));
echo "終了ステータスの値: "$?

実行結果1
# sh test03.sh
5
6
終了ステータスの値: 1

実行結果2
# sh test03.sh
89
89
終了ステータスの値: 0

shellscript

Posted by arkgame