On linux system, is there any difference to kick of script.sh in these two different ways?
Are they exactly the same thing?
Thanks
On linux system, is there any difference to kick of script.sh in these two different ways?
Are they exactly the same thing?
Thanks
Is not necessarily the same.
If you run script.sh linux will search on the directories set in the $PATH env variable.
With ./script.sh, linux will run the script located on the directory where you are at the moment of the call.
In order for the first form to work, the file must have the executable bit set, secondly it needs to have a shebang which specifies which interpreter that will be used.
So yes, both forms are identical (when it comes to what will be interpreted).
For a history-lesson see this
Current implementation of the she-bang parsing in the linux-kernel can be found here
I don't think this is exactly the same.
As far as I understand, you simply execute a script with
./script.sh
on the current shell. It hasn't to be a bash (Bourne Again SHell) you're running, it can be any shell installed on your system.If you execute a script with
bash script.sh
, you tell the system that you want the script to be executed explicitly with a bash shell.You can see which shells are available for your system by calling:
./script.sh expects that this file is in the current directory, has execute bit set and the first line of the file is path to the interpreter to start with ( Shebang line )
bash script.sh means that you invoke bash and pass the contents of the file to be executed(interpreted) as bash commands. This way your file doesn't need to be executable and has a shebang line.
If the conditions for ./script.sh are met then both invocations lead to the same result.
script.sh can be called script.anything as pointed on on the knittl post within bully, the script is identified by
running bash ./script.something means your telling it to execute the script using bash and this can return errors rather than run also bully forgot
so you could have a perl script called script.sh