How to run multiple Unix commands in one time?

前端 未结 8 1423
一向
一向 2021-02-06 02:04

I\'m still new to Unix. Is it possible to run multiple commands of Unix in one time? Such as write all those commands that I want to run in a file, then after I call that file,

8条回答
  •  甜味超标
    2021-02-06 02:43

    Short answer is, yes. The concept is known as shell scripting, or bash scripts (a common shell). In order to create a simple bash script, create a text file with this at the top:

    #!/bin/bash
    

    Then paste your commands inside of it, one to a line.

    Save your file, usually with the .sh extension (but not required) and you can run it like:

    sh foo.sh
    

    Or you could change the permissions to make it executable:

    chmod u+x foo.sh
    

    Then run it like:

    ./foo.sh
    

    Lots of resources available on this site and the web for more info, if needed.

提交回复
热议问题