我有一個簡單的腳本命名爲example
:擊:單引號和雙引號和感嘆號
#!/bin/sh
echo $'${1}'
請注意,$''
使用這裏是\n
轉換成新的生產線。 ${1}
是傳遞給此shell腳本的第一個參數。
我想一個參數傳遞給該腳本example
並打印如下:
#1. You're smart!
#2. It's a difficult question!
我試過如下:
example "#1. You're smart!\n#2. It's a difficult question!"
錯誤:-bash: !\n#2.: event not found
然後我試圖以單引號轉義!
,並嘗試:
example '#1. You're smart\!\n#2. It's a difficult question\!'
它輸出:
${1}
任何解決辦法嗎?非常感謝!
墊提供了完美的解決方案!感謝Chris Jester-Young和Jan Hudec。所有專家! – DocWiki 2011-05-16 12:16:31