シェルスクリプトparent.shのようなものがあります。私はchild.shで使用する変数フラグをしたい、そこフラグの値を更新し、parent.shに戻って更新された値を取得します。どうすればこれを実現できますか?他のスクリプトのシェルスクリプト変数へのアクセスとアップデート
#!/bin/bash
flag=999 #I want ths flag in child.sh and there i will update its value depending on some condition
$HOME/child.sh
if [ $? -eq $flag ];then #The value of flag got changed on child.sh
echo "Success"
else
echo "Failed"
fi
そして
#!/bin/bash
hive -f $HOME/creat.hql #It should be create.hql so it will fail.
if [ $? -eq 0 ];then
flag=0
else
flag=1 #This will execute and I want this change to be get reflected in parent.sh
fi
なぜ、child.shの戻り値と変更されたフラグ変数の両方を使用しようとしていますか? child.shの最後に 'exit $ flag'を置いて、' if [$ flag -eq 0];を使うことができます。 ... –
_child.sh_の変数_flag_にアクセスする方法 – MrG
呼び出しの直後に 'flag = $?'を使用すると、( 'exit $ flag'で設定した)戻り値をスクリプト)。スクリプトのフラグ値は使用しませんが、同じ値を使用します(値は0〜127しかないと仮定します)。私は 'if [$? -eq 0];それで...上記のコメントで "成功"をエコーしますが、終了値を変数に代入する方が安全です。もちろん、 'flag'と呼ぶこともできます。 –