[英]Run bash commands from txt file
I have some commands in txt file and I need to execute all them line by line. 我在txt文件中有一些命令,我需要逐行执行它们。 How could I do it? 我怎么能这样做?
Just do bash file
: 只做bash file
:
$ cat file
date
echo '12*12' | bc
$ bash file
Mon Nov 26 15:34:00 GMT 2012
144
In case of aliases just run bash -i file
如果是别名,只需运行bash -i file
No need to worry about file extensions or execution rights. 无需担心文件扩展名或执行权。
In a Terminal just type: 在终端中输入:
bash path/to/my/file.txt
And you will get each lines executed. 你会得到每一行。
just change the extension of the file to .sh 只需将文件的扩展名更改为.sh即可
add /bin/bash at starting of the file 在启动文件时添加/ bin / bash
change the permission of the file to executable 将文件的权限更改为可执行文件
than simply run ./filename.sh command in command line. 而不是简单地在命令行中运行./filename.sh命令。 all the commands in the file will be executed 将执行文件中的所有命令
将扩展名更改为.sh并将第一行更改为#!/usr/bin/env bash
并且正如其他人所说的chmod +x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.