どの行が正しいですか?私は仕事を段階的に行います。
if [ $? -ne 0 ]; then
正確な説明が見つかりませんでしたが、-ne
この行は最後に行った操作が成功したことを確認することを理解しています。
ksh $PROC/reg.sh 2>&1 | tee $REG
ksh
つまり、PROCのreg.shでkornシェルを使用し、2>&1はstderrを指定されていないファイルにリダイレクトし、sterrはstdoutにリダイレクトします。 (何をしているのか、目的が何なのかわかりません| tee $REG
。)
cat $REG >> $DD_LIBEDIT/log.$DATE
cat
接続に使用しましたが、この行には1つのファイルしかありません。これはREGがログに接続されることを意味しますか?
This.$DATE (DATE=`date +%Y%m%d)
ログに日付が追加されますか?
これはバッチの小さな部分に過ぎず、多くの研究を経ても意味を理解できない部分を選択しようとしました。
ベストアンサー1
シェルのマニュアルページが役に立つことがよくあります。最初の例を挙げましょう。
if [ $? -ne 0 ]; then
私のシステムでは、man ksh
次のように言います。
if list ;then list [ ;elif list ;then list ] ... [ ;else list ] ;fi
The list following if is executed and, if it returns a zero exit sta‐
tus, the list following the first then is executed. Otherwise, the
list following elif is executed and, if its value is zero, the list
following the next then is executed. Failing each successive elif
list, the else list is executed. If the if list has non-zero exit
status and there is no else list, then the if command returns a zero
exit status.
特に、これは「リスト」、すなわち実行される命令がif
その間にあることを意味する。then
リストの実際のコマンドはです[
。これはコマンドとシェルの組み込みです。
$ type -a [
[ is a shell builtin
[ is /usr/bin/[
man [
コマンドおよびman ksh
組み込みコマンドに使用されます。 (Bashの場合、help [
組み込みの詳細も提供します。)
ほとんどの場合、コマンドについて話しているのか、組み込みコマンドについて話しているのかは関係ありません。man [
それでは、次のように話してください。
INTEGER1 -ne INTEGER2
INTEGER1 is not equal to INTEGER2
あなたの場合、$?
その変数の値を0と比較します。別の外観を見てくださいman ksh
:
The following parameters are automatically set by the shell:
? The decimal value returned by the last executed command.
戻り値がゼロの場合、通常はすべてが正常であることを意味します。 (ただし、特定のコマンドについてはマニュアルページを確認して確認してください。)
したがって、if [ $? -ne 0 ]; then
前のコマンドは単にエラーがあるかどうかを確認します。
このcat
コマンドはすべてのファイルを読み込み、標準出力に出力します。その後、シェルを使用してファイルにリダイレクトできます。別の外観を見てくださいman ksh
:
>>word Use file word as standard output. If the file exists, then
output is appended to it (by first seeking to the end-of-file);
otherwise, the file is created.