1. Invoke
Having written the script, you can invoke it by bash scriptname.
Much more convenient is to make the script itself directly executable with a chmod.
$ chmod 555 scriptname (gives everyone read/execute permission) or
$ chmod +rx scriptname (gives everyone read/execute permission)
2. Test
Having made the script executable, you may now test it by
./scriptname
For example:
$ cat >test_chmod << "EOF" # Create a (script) file named test_chmod.
> #!/bin/bash # the "sha-bang" line. Indicate calling command interpreter.
> echo "Hello,bash world!" # Write a script command.
> EOF # End the file.
$ chmod 555 test_chmod # Invoke the script file, gives everyone read/execute permission.
$ ./test_chmod # test it!
Hello,bash world! # The script file was run.
3. "sha-bang" line
#!/bin/sh
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/tcl
#!/bin/sed -f
#!/bin/awk -f
Each of the above script header lines calls a different command interpreter, be it /bin/sh, the default shell
(bash in a Linux system) or otherwise.
Note: $chmod 4755 filename # Give filename root permission.