Run text files in terminal

前端 未结 4 1617
小鲜肉
小鲜肉 2021-02-04 16:20

Does anyone know if there\'s a way to run automatically in shell a list of commands (from a text file)?

I need to run a lot of scripts (around 1000). The scripts are in

相关标签:
4条回答
  • 2021-02-04 16:31

    Also, you can run a shell file by:

    source filename
    
    0 讨论(0)
  • 2021-02-04 16:45

    You can write a shell script:

    #! /bin/sh
    
    python /home/name/scripts/get_info.py dir_1 sample1
    python /home/name/scripts/get_info.py dir_2 sample2
    python /home/name/scripts/get_info.py dir_3 sample3
    python /home/name/scripts/get_info.py dir_4 sample4
    ...
    
    0 讨论(0)
  • 2021-02-04 16:47

    Either make the file executable:

    chmod u+x thefile
    ./thefile
    

    or run it as an argument of sh:

    sh thefile
    
    0 讨论(0)
  • 2021-02-04 16:48

    That's called a "shell script."

    Add this to the top of your file:

    #!/bin/sh
    

    Then execute this command:

    chmod +x filename
    

    Then execute it like a program:

    ./filename
    

    Alternately, you can execute the shell directly, telling it to execute the commands in your file:

    sh -e filename
    
    0 讨论(0)
提交回复
热议问题