我经常会将常用的命令写在一个记事本中
这样想执行时,可以方便的操作
比如
cat shell.txt
pwd
date
ls
这个时候该如何执行shell.txt的内容呢
比如想执行date
root@orangepipc:~# eval `cat 1.txt|sed -n '2p'`
或
root@orangepipc:~# eval $(cat 1.txt|sed -n '2p')
想执行ls
root@orangepipc:~# eval `cat 1.txt|tail -1`
或
root@orangepipc:~# eval $(cat 1.txt|tail -1)
我们还可以逐行读取并执行
!/bin/bash
while read -r line
do
echo $line
eval $line
done < shell.txt
或者
#!/bin/bash
for i in `cat 1.txt`
do
eval $i
done
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:shell读取文件的内容作为命令执行 出自老鄢博客 | 欢迎分享