r/bash • • Dec 02 '14

Using #! in your scripts

http://shiroyasha.github.io/shebang.html
0 Upvotes

24 comments sorted by

View all comments

5

u/geirha Dec 02 '14

Don't put extensions on scripts. Especially not .sh when the script isn't even an sh script.

4

u/nath_schwarz Dec 02 '14

Don't put extensions on scripts.

Bullshit. If there is a suffix or not doesn't matter for the environment, it only matters for you if you need to find every *zsh or *bash-script on your system or in a specific folder.

If you're working with multiple shells you'll need that. If you only use one it doesn't matter.

What if you have bash and python scripts? If you want to search and list only your python-pieces you'd need to go into every file and grep the first line to see if it uses #!/usr/bin/env python or #!/usr/bin/env bash. So, instead of find -type f \*py you'll need to use grep (slooow) or silver searcher/ack (and even these will be slower since you need to access the file every time - not only the filename).

Especially not .sh when the script isn't even an sh script.

That, on the other hand, is correct.

1

u/[deleted] Dec 02 '14

On a side note: Check out the file command on Linux. You don't have to do all the madness grepping for shebang lines.

1

u/sbicknel 1,$s/n\?vim\?/ed/g Dec 08 '14

Exactly.

for f in *; do
    if ! [[ $(file -b --mime-type "$f") =~ perl ]]; then
	    continue
    fi
    ...
done