2014-03-29 35 views
1

我不知道這裏發生了什麼。我做了比我分享的bash腳本更多的東西。搜索過去的問題讓人們詢問如何使報價持久。Bash腳本在我不想要的時候迴應雙引號

當回顯至/ dev/tty時,引號也回顯。

例子:

#!/bin/sh 
OLDIFS=$IFS 
IFS=$'\n' 
currentfile=This.File; 
echo 'About to output' > /dev/tty; 
echo 「The Currect File is $currentfile」 > /dev/tty; 
IFS=$OLDIFS 

這將呼應:

\#'About to output' 
\#"The Currect File is ?? 

如果我把$ currectfile後的空間,我會得到一個更正確的,但不是我要尋找的:

\#'About to output' 
\#"The Currect File is This.File " 

我期待的輸出很簡單:

\#About to output 
\#The Currect File is This.File 

當在交互中輸入此行時,會如預期的那樣回顯。

+0

雖然我只是做一個例子,我執行我的示例程序,並得到Macbook-Pro-15的輸出:桌面用戶$ bash anotherDirectory/test.sh 關於輸出 「The Currect File is ?? Macbook-Pro-15:桌面用戶$ sh anotherDirectory/test.sh 關於輸出 「The Currect File is ??所以雖然單引號不在這裏,但在我的主程序中顯示雙引號是相同的。 – user259685

+4

看起來您的代碼中有U + 201C(左側雙引號)和U + 201D(右側雙引號),與U + 0022(引號)相反。 – Biffen

+0

正確!我只需要改變他們。謝謝 – user259685

回答

2

我們來運行你的代碼通過shellcheck自動檢查常見問題:

echo 「The Currect File is $currentfile」 > /dev/tty; 
    ^-- SC1015: This is a unicode double quote. Delete and retype it. 

而且我們做到這一點:

echo "The Currect File is $currentfile" > /dev/tty; 
相關問題