I have some commands in txt file and I need to execute all them line by line. How could I do it?
Just do 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
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
add /bin/bash at starting of the file
change the permission of the file to executable
than simply run ./filename.sh command in command line. all the commands in the file will be executed
将扩展名更改为.sh并将第一行更改为#!/usr/bin/env bash
并且正如其他人所说的chmod +x
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.