包含在bash空间执行命令 [英] Executing commands containing space in bash
本文介绍了包含在bash空间执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件名为CMD包含UNIX命令的列表如下:
I have a file named cmd that contains a list of unix commands as follows:
hostname
pwd
ls /tmp
cat /etc/hostname
ls -la
ps -ef | grep java
cat cmd
我还有一个脚本,在cmd中执行命令为:
I have another script that executes the commands in cmd as:
IFS=$'\n'
clear
for cmds in `cat cmd`
do
if [ $cmds ] ; then
$cmds;
echo "****************************";
fi
done
问题是,没有空格CMD命令运行良好,但那些与空间都没有正确的脚本PTED间$ P $。以下是输出:
The problem is that commands in cmd without spaces run fine, but those with spaces are not correctly interpreted by the script. Following is the output:
patrick-laptop
****************************
/home/patrick/bashFiles
****************************
./prog.sh: line 6: ls /tmp: No such file or directory
****************************
./prog.sh: line 6: cat /etc/hostname: No such file or directory
****************************
./prog.sh: line 6: ls -la: command not found
****************************
./prog.sh: line 6: ps -ef | grep java: command not found
****************************
./prog.sh: line 6: cat cmd: command not found
****************************
我是什么在这里失踪?
What am I missing here?
推荐答案
试着改变一行 EVAL $ CMDS
而不仅仅是 $ CMDS
Try changing the one line to eval $cmds
rather than just $cmds
这篇关于包含在bash空间执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文