最初来自:如果格雷普(Grep
$@具有" load Firefox/3.6.12"
的值var1=$(echo "$@" | grep -Eio 'sw*') # Gets the application name and put it into var1
echo $var1 # is not printed should be "firefox"
var2=$(echo "$@" | grep -o '[^/]*$') # Gets version name and put it into var2
echo $var2 # prints fine
正则是很好的
编辑:
有问题var1=$(echo "$@" | grep -Eio 'sw*') #expected result is: firefox
如果我使用
,我的工作正常var1="firefox"
我一定已经改变了某个点。
编辑:解决方案
echo "Load firefox/6.12.3" | awk ‘{print $2}’ | cut -f1 -d”/”
不再使用GREP。
在运行之前尝试回音 - 似乎您需要修剪var1 var2
的文本echo" find/app/$ var1 -noleaf -maxDepth 1 -type l -o -o -type d | grep $ var2"
if find /app/$var1 -noleaf -maxdepth 1 -type l -o -type d | grep $var2; then
find/app/ firefox -noLeaf -maxDepth 1 -Type l -o -o -type d |GREP 3.6.12
所以尝试:
var1=${var1//[[:space:]]}
var2=${var2//[[:space:]]}
if find /app/$var1 -noleaf -maxdepth 1 -type l -o -type d | grep $var2; then