Friday, May 3, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 1223  / 3 Years ago, sat, june 19, 2021, 4:54:16

I have a server where I have different kinds of scripts.


Those scripts are to be opened with different shells such as:


sh ./do_one_thing.sh
bash ./do_another_thing.sh

the .sh extension is dangerous to me especially if I have not connected to the server for a longer time. Or if someone unfamilliar needs to do a stand-in.

I might accidently execute sh ./do_another_thing.sh


Will it make any difference if I name my script do_another_thing.bash? This would create one more layer of foolproofness.


Additionally, I would like to know what the shebang line in the beginning is for other than a reminder to the Admin (#!/bin/bash) if it get's overwritten by sh ./do_another_thing.sh anyways. It seems to me such that there must be a more proper way of executing the script, recogniting the shebang.


More From » command-line

 Answers
0

The shebang at the top of the file defines what interpreter is run when you run ./name_of_file (assuming it's executable).


#!/bin/cat
test 123

will simply print the above file when you run it with ./name_of_file, as it will run cat name_of_file.


#!/bin/echo
hello, world

will simply print name_of_file, because it runs echo name_of_file.


Setting that to bash or sh will allow you to choose what interpreter it runs with, as long as you remember to invoke it with ./name_of_file.


That being said, using .sh for sh, and .bash for bash works fine, albiet non-standard. File extensions are fairly fluid on linux.


[#976] Saturday, June 19, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
istmasted

Total Points: 287
Total Questions: 130
Total Answers: 153

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
istmasted questions
;