これがどのように機能するかです
MPBAB:work anj$ cat test.sh
echo "Hello there"
echo "This is a test script"
badcommand
MPBAB:work anj$ ./test.sh 2> err.log
Hello there
This is a test script
MPBAB:work anj$ cat err.log
./test.sh: line 4: badcommand: command not found
ご覧のとおり、test.sh
呼び出そうとするとbadcommand
エラーがスローされます。ただし、2 つのecho
ステートメントは問題なく機能し、 に表示されSTDOUT
、STDERR
は にログインしerr.log
ます。
今あなたが試した方法を実装しています-
MPBAB:work anj$ ./test.sh . 2>err.log
Hello there
This is a test script
MPBAB:work anj$ cat err.log
./test.sh: line 4: badcommand: command not found
同じように動作します。あなたの場合、scp
あなたが発行しているコマンドは正しくないと考えざるを得ません。とscp
が必要です。このようなもの( test.txtをリモートサーバーに送信したい場所)source
destination
scp
MPBAB:work anj$ scp ./test.txt user@secure.server.com:/home/data 2>scperr.txt
user@secure.server.com's password: #<this is because I dont have the public key installed>
test.txt 100% 291 0.3KB/s 00:00
MPBAB:work an$ cat scperr.txt
MPBAB:work anj$
ご覧のとおり、ファイルがコピーされ、test.txt 100% 291 0.3KB/s 00:00
エラーSTDOUT
がなかったためscperr.txt
空でした。