原籍:IF grep finds what it is looking fore do X else Y但原來的問題得到回答。擊:變量不填充
$ @擁有的「加載的Firefox/3.6.12」值
var1=$(echo "[email protected]" | grep -Eio '\s\w*') # Gets the application name and put it into var1
echo $var1 # is not printed should be "firefox"
var2=$(echo "[email protected]" | grep -o '[^/]*$') # Gets version name and put it into var2
echo $var2 # prints fine
正則表達式是好的,它之前的一次前我改變了一些東西的工作
編輯: 有有毛病
var1=$(echo "[email protected]" | grep -Eio '\s\w*') #expected result is: firefox
我工作正常,如果我使用
var1="firefox"
我一定改變的東西一些點。
編輯: SOLUTION
echo "Load firefox/6.12.3" | awk ‘{print $2}’ | cut -f1 -d」/」
的grep不再使用。
檢查輸入($ @)。我剛剛加載腳本並將其作爲./腳本運行。加載firefox/3.6.12,我得到了您期望的輸出。 –
必須有一個腦凍結。這是行不通的: echo「Load firefox/6.12.3」| grep -Eio'\ s \ w *' – Fredrik
可能是您的系統。在我的標準輸出上打印「firefox」。 –