在Bash中将文本文件作为命令运行 [英] Run text file as commands in Bash
本文介绍了在Bash中将文本文件作为命令运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在每行上都有一个单独的命令的文本文件,我如何使终端作为命令运行每行?我只是不想一次复制和粘贴1行.它不必是文本文件,而可以是任何可以使用的文件.
If I have a text file with a separate command on each line how would I make terminal run each line as a command? I just don't want to have to copy and paste 1 line at a time. It doesn't HAVE to be a text file... It can be any kind of file that will work.
example.txt
:
sudo command 1
sudo command 2
sudo command 3
推荐答案
您可以使用以下命令创建一个shell脚本,然后使用chmod +x <scriptname.sh>
,然后通过
you can make a shell script with those commands, and then chmod +x <scriptname.sh>
, and then just run it by
./scriptname.sh
编写bash脚本非常简单
Its very simple to write a bash script
样机sh文件:
#!/bin/sh
sudo command1
sudo command2
.
.
.
sudo commandn
这篇关于在Bash中将文本文件作为命令运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文