Run a sh script

Solved
Hello.

Having been on Linux for a short while, I'm trying to create small bash scripts. However, I don't know how to execute them. Is there a specific command to run the script from a console?

Thank you in advance.

1 answer

  1. Moderator
    Hello,
    • either you specify the path to the command interpreter on the first line of your script

    johand@horus:~/src/bash$ cat hello.sh #!/bin/sh echo ${USER}


    you mark it as executable:
    johand@horus:~/src/bash$ chmod 744 hello.sh johand@horus:~/src/bash$ ./hello.sh johand
    • or you run it directly with sh or bash (under Linux, sh is usually a link to bash)

    sh hello.sh bash hello.sh


    Attention
    Sourcing the file runs the execution IN THE CURRENT SHELL.
    If there is an exit instruction, for example, you are ejected from the current shell.

    Johan

    Gates gave you the windows.
    GNU gave us the whole house.(Alexandrine)
    103
    1. Great, I understood, thank you!
      2
    2. Thank you, I've been struggling for a long time to create a reinstallation script.
      0
    3. Interesting: the command "watch" (in Bash) which allows you to repeatedly execute a command at specified time intervals.
      0
    4. Thank you for your help.
      0
    5. Thank you for your help.
      0