網頁

2017年10月19日 星期四

Catch exit code in bash shell script

The key variable is $?

Example code :

#!/bin/bash

./execute_some_script.sh

if (( $? == 0 ))
then
    echo "the script in script was executed successfully."
else
    echo "the script in script was failed !"
fi

Also a tip for comparing variable as numeric is " if (( $var op $another_var_or_number )) "

沒有留言:

張貼留言

Python TypeError: 'module' object is not callable

程式碼其實相當簡單 import random random.random() 那問題出在哪?出在當初的檔名取名為 random.py 結果造成 Python 在 import 的時候造成問題。所以在取名Python 的檔名時,切記不要取成跟 Default Module...