0

I have create several Linux scripts to automate task and find that You can execute on any of those ways, is there any difference or are they equivalent?, below an example using restartRemoteQAServer.sh

-bash-4.2$sh restartRemoteQAServer.sh

Is there any difference or is It equivalent to

-bash-4.2$./restartRemoteQAServer.sh
Enrique Palacio
  • 1,521
  • 13
  • 8
  • 3
    `sh foo` is running `sh`, not `bash`. Not the same language. – Charles Duffy Feb 12 '20 at 21:16
  • 2
    ...whereas `./whatever` runs whatever interpreter the shebang in `whatever` specifies, which might not be a shell at all (could be Python, could be Ruby, could be Node, could be whatever). – Charles Duffy Feb 12 '20 at 21:17
  • 1
    `./` uses the shebang, so for example if it's `#!/usr/bin/env python3`, the script will be run with `python3`, not a shell. – wjandrea Feb 12 '20 at 21:17
  • 1
    BTW, there's an informative essay by @erlkonig [on why `.sh` (and other) extensions on UNIX commands are harmful](http://www.talisman.org/~erlkonig/documents/commandname-extensions-considered-harmful/). As you can see via the irc.freenode.org #bash [`.sh` factoid history](http://wooledge.org/~greybot/meta/.sh), this has been in line with general community consensus for quite some time. – Charles Duffy Feb 12 '20 at 21:20
  • 1
    Just keep it consistent with whatever you generally use for executables. For example, if you list directories with `/lib64/ld-linux-x86-64.so.2 /bin/ls` you can use `sh restartRemoteQAServer` for consistency. Personally, I use `ls` so I would similarly use `restartRemoteQAServer` or `./restartRemoteQAServer` as appropriate. – that other guy Feb 12 '20 at 21:28

0 Answers0