当我执行以下操作时,会得到结果:
bash$ cat launched | egrep MyTest
MyTest
但有了以下脚本:
#!/bin/sh
result= `cat launched | grep MyTest`
echo $result
启动脚本时,我得到:
bash$ ./test.sh
./test.sh: MyTest: not found
我对脚本具有完全访问权限,并且脚本与启动的文件在同一目录中启动。如何修复脚本,使其返回与上面相同的结果?
最佳答案
放下空间:
result=`cat launched | grep MyTest`
更妙的是,放下UUOC:
result=`grep MyTest launched`
关于linux - 如何在脚本中执行grep?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8154637/