是用 exit 指令。
exit 123然後 caller 用 $? 就可以取得上一個 script exit 的值。
exit 123然後 caller 用 $? 就可以取得上一個 script exit 的值。
$ echo '0 [123] 456' | sed 's/\[.*\]//' 0 456
$ssh-keygen -t rsa
$scp .ssh/id_rsa.pub a_server:~
$cat id_rsa.pub >> .ssh/autorized_keys
$ ssh-add Identity added: /home/charles-chang/.ssh/id_rsa (/home/charles-chang/.ssh/id_rsa)
Agent admitted failure to sign using the key.
/etc/crontab
. .profile
$?
cd mydir
if [ "$?" -ne "0" ]; then
echo failed
else
echo success
fi
make -j4 2>&1 | tee makelog
這時候用 $? 就會是 tee 這個 command 執行的結果,不是 make 的
make -j4 2>&1 | tee makelog
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
echo failed
else
echo success
fi
<name>Charles</name>
<id>123</id>
<color>red</color>
...
<.*> \(.*\) <\/.*>
sed 's/ <.*>\(.*\)<\/.*> / \1 /' file
一樣用 s 指令。sed 's/ <id>\(.*\)<\/id> / \1 /' file