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