我發現了這一點,在試圖鞏固我的腳本字符串安全:這是GNU Bash中的一個錯誤嗎?
$ echo '!!'
!!
$ echo "$(echo '!!')"
echo "$(echo 'echo '!!'')" #<~ the console echoes the line with expanded history here
echo !! #<~ the result
在我看來,最裏面的報價,這是單引號,應該不擴大什麼,可變的,子shell或其他,但在這種情況下,它將!!
擴展到最後一行類型。似乎不應該那樣做。
我問你:這是一個Bash中的錯誤,並且如果可以使用一個帶引號的子shell擴展輸出感嘆號?
(在Linux中使用bash 4.1.007)
編輯:
如果上面的是不是一個錯誤,爲什麼,那麼,這是否像預期的那樣?
$ foo='some value'
$ echo "$(echo 'neither $foo nor `this subshell` should expand here')"
neither $foo nor `this subshell` should expand here
不是一個錯誤。這是bash如何擴展論證。有人會參考手冊的相關部分回答。 – Juliano 2011-02-13 16:44:35