在 Bash 中将文本文件作为命令运行 [英] Run text file as commands in Bash

查看:36
本文介绍了在 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 ,然后直接运行它由

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆