Scripts

A script is a (bash) program. It consists of grouping a command set in a file and giving the rights in execution of this file.

The first line of the script is a particular line, indicating to the operating system that it is the interpreter to use. In this case, the line starts by #! followed by the path to the shell.1

In bash, any line starting with a # is not interpreted beyond that # .

# indicates the start of a comment.

A command line in bash ends either by a carriage return (\n), either by a semi-colon (;).

If a command must continue to the next line, the continuation character \ must be used.

#!/bin/bash
echo Hello
# a comment
ls
echo a; echo b
echo hello\
world

Example:

cat > script1 << END
#!/bin/bash
echo Hello
END
chmod +x script1
./script1

  1. this can be obtained via the which command