2
私は関数のコマンドの終了ステータスをチェックしてローカル変数に格納すると、常に答えが0になります。関数の外から、正しい終了ステータスが得られます。bashスクリプト - 関数内でチェックされていれば、前のコマンドの終了ステータスが異なります。
#!/bin/bash
function check_mysql()
{
local output=`service mysql status`
local mysql_status=$?
echo "local output=$output"
echo "local status=$mysql_status"
}
check_mysql
g_output=`service mysql status`
g_mysql_status=$?
echo "g output=$g_output"
echo "g status=$g_mysql_status"
出力は:
local output=MySQL is running but PID file could not be found..failed
local status=0
g output=MySQL is running but PID file could not be found..failed
g status=4
4のステータスが正しいものです。
パーフェクト - あなたに感謝。 – user265330