我不確定我得到的語法錯誤是否真的是語法錯誤。
timeout 120 bash -c "date && (time nc -z -v -w 10 -q 60 google.com 443 && date) || {echo 'running command failed.' ; date ; exit 1 ; }"
語法錯誤:
bash: -c: line 0: syntax error near unexpected token `}'
uj5u.com熱心網友回復:
它抱怨關閉的卷曲,因為它沒有看到一個開放的卷曲 -
這是因為它需要空格將其與 分開echo以使其成為一個獨特的東西。
$: bogus && echo ok || {echo 'running command failed.' ; date ; exit 1 ; }
-bash: syntax error near unexpected token '}'
$: bogus && echo ok || { echo 'running command failed.' ; date ; exit 1 ; }
-bash: bogus: command not found
running command failed.
Mon Jun 20 18:16:02 GMT 2022
logout
問題的真正根源:
$: {echo 'running command failed.'
bash: {echo: command not found
把它放在它運行良好的空間。
$: timeout 120 bash -c "date && (time nc -z -v -w 10 google.com 443 && date) || { echo 'running command failed.' ; date ; exit 1 ; }"
Mon Jun 20 18:11:46 GMT 2022
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 2607:f8b0:4004:837::200e:443.
Ncat: 0 bytes sent, 0 bytes received in 0.04 seconds.
real 0m0.039s
user 0m0.007s
sys 0m0.008s
Mon Jun 20 18:11:46 GMT 2022
嘗試在https://www.shellcheck.net/一次粘貼一塊
Line 2:
{echo 'running command failed.' ; date ; exit 1 ; }"
^-- SC1054 (error): You need a space after the '{'.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/493695.html
