Run bash commands from txt file

前端 未结 4 673
耶瑟儿~
耶瑟儿~ 2020-12-08 00:11

I have some commands in txt file and I need to execute all them line by line. How could I do it?

相关标签:
4条回答
  • 2020-12-08 00:26

    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

    0 讨论(0)
  • 2020-12-08 00:30

    Change the extension to .sh and for the first line #!/usr/bin/env bash and as someone else said chmod +x

    0 讨论(0)
  • 2020-12-08 00:36

    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.

    0 讨论(0)
  • 2020-12-08 00:41

    In a Terminal just type:

    bash path/to/my/file.txt
    

    And you will get each lines executed.

    0 讨论(0)
提交回复
热议问题