Hi
I'm not 100% sure what you are asking,bit if i understand you correctly, that does not tell gedit where to save the script. You need to tell gedit where to save the file and give it a file name.
What this does is to specify what shell should be used to run the script when the script is run as an executable file with the executable bit set in it's permissions and you do not specify which shell to run it with from the command line.
Code:
matthew-Aspire-7540:/home/matthew % cat script
#!/bin/bash
# My first script
echo "Hello World!"
matthew-Aspire-7540:/home/matthew % chmod 755 script
matthew-Aspire-7540:/home/matthew % ll script
-rwxr-xr-x 1 matthew matthew 52 Oct 9 18:18 script*
matthew-Aspire-7540:/home/matthew % ./script
Hello World!
Without the executable bit set you cannot run the script that way......
Code:
matthew-Aspire-7540:/home/matthew % chmod 664 script
matthew-Aspire-7540:/home/matthew % ll script
-rw-rw-r-- 1 matthew matthew 52 Oct 9 18:18 script
matthew-Aspire-7540:/home/matthew % ./script
zsh: permission denied: ./script
matthew-Aspire-7540:/home/matthew %
....but you can run it without the executable bit set script if you state the shell to run it with though on the command line.
Code:
matthew-Aspire-7540:/home/matthew % ll script
-rw-rw-r-- 1 matthew matthew 52 Oct 9 18:18 script
matthew-Aspire-7540:/home/matthew % bash script
Hello World!
matthew-Aspire-7540:/home/matthew %
There are a number of shells you can use to run scripts and by putting the shebang (!#) and the path to the shell as the first line of your script, you specify which shell to run the script when the script is run as an executable file.
You can get an idea of the shells on your system by looking at /etc/shells. Here's mine
Code:
matthew-Aspire-7540:/home/matthew % cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/screen
/usr/bin/tmux
/bin/zsh
/usr/bin/zsh
/bin/csh
/bin/tcsh
/usr/bin/tcsh
matthew-Aspire-7540:/home/matthew %
You can specify different shell to run your script by changing the shebang line (i.e #!/bin/dash) and, when run as an executable script, it will run the script using that shell.
This, below, will change the shell to dash in the file, check it and run the script using the dash shell.
Code:
matthew-Aspire-7540:/home/matthew % sed -i 's/bash/dash/' script
matthew-Aspire-7540:/home/matthew % head -n1 script
#!/bin/dash
matthew-Aspire-7540:/home/matthew % ./script
Hello World!
matthew-Aspire-7540:/home/matthew %
Note there are differences between the shells and some commands wont work in some shells.
csh and tsch even have a completely different syntax more in line with the C programming language.
I hope i understood your question correctly and i hope that made sense.
Kind regards
Bookmarks