Scripting help needed... [SOLVED]

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Message
Author
User avatar
Head_on_a_Stick
Posts: 919
Joined: Sun Mar 17, 2019 3:37 pm

Re: Scripting help needed...

#11 Post by Head_on_a_Stick »

manyroads wrote: Mon Jul 15, 2019 9:19 am

Code: Select all

#bin/bash
If you want to explicitly specify bash for your script then you need to add an exclamation mark after the # symbol to make a shebang.

However, bash is bloated, buggy & slow and your script does not use any of the special features of that shell (known as bashisms) so you could speed it up by using a POSIX shebang instead:

Code: Select all

#!/bin/sh
In MX /bin/sh is symlinked to dash and that is preferred over bash for system scripts.

Silly benchmark:

Code: Select all

E485:~$ time bash -c 'for i in $(seq 1 1000000);do [ 1 = 1 ];done'
    0m03.97s real     0m03.83s user     0m00.16s system
E485:~$ time dash -c 'for i in $(seq 1 1000000);do [ 1 = 1 ];done'
    0m01.45s real     0m01.42s user     0m00.06s system
E485:~$
So dash is more than twice as fast as bash, uses less memory and is less buggy. The difference won't really be apparent for your one-liner but it is the best option.
mod note: Signature removed, please read the forum rules

User avatar
manyroads
Posts: 2624
Joined: Sat Jun 30, 2018 6:33 pm

Re: Scripting help needed... [SOLVED]

#12 Post by manyroads »

Thank you @Head_on_a_Stick. I have made the change.

EDIT The #!/bin/sh made a mess of the formatting... I changed it to: #!/bin/bash Things seem okay now.
Pax vobiscum,
Mark Rabideau - ManyRoads Genealogy -or- eirenicon llc. (geeky stuff)
i3wm, bspwm, hlwm, dwm, spectrwm ~ Linux #449130
"For every complex problem there is an answer that is clear, simple, and wrong." -- H. L. Mencken

Post Reply

Return to “Tips & Tricks by users”