SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2015-09-05 04:15:17

flaneur
#! Member
Registered: 2014-01-24
Posts: 99

Unnecessarily using Bash instead of sh?

#!/usr/bin/env bash

# hint: use "xdotool getmouselocation" to get values for your situation

xgg="$(xdotool getactivewindow getwindowname)"

if [[ "$xgg" == *" - LibreOffice Calc" ]]
  then
    xdotool mousemove --sync 218 144 click 1
fi

Offline

Be excellent to each other!

#2 2015-09-05 08:04:59

ostrołęk
CB Member
Registered: 2015-08-13
Posts: 110

Re: Unnecessarily using Bash instead of sh?

Offline

#3 2015-09-05 09:31:30

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: Unnecessarily using Bash instead of sh?

Offline

#4 2015-09-05 09:37:34

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Unnecessarily using Bash instead of sh?

it's mostly a question of portability i think.

on my system, /usr/bin/sh is just a link to bash, and /bin is just a link to /usr/bin.
so it doesn't really matter whether i use #!/bin/bash or "!/usr/bin/sh or any other combo. (*) (**)

what matters is that all my scripting experience is in bash, and i wouldn't even be able to say if my script would run on another shell.
so, to be on the safe side, i use #!/bin/bash.

(*) please correct me if i'm wrong

(**) ostrolk, on debian these things are a little different. but, at least for the question asked here, it shouldn't matter whether bash is in /bin or /usr/bin, as long as it's in your $PATH.
about env: try "man env".

Offline

#5 2015-09-05 09:42:22

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: Unnecessarily using Bash instead of sh?

# ln -sfT dash /bin/sh

Offline

#6 2015-09-05 10:20:56

ostrołęk
CB Member
Registered: 2015-08-13
Posts: 110

Re: Unnecessarily using Bash instead of sh?

Offline

#7 2015-09-05 10:35:06

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Unnecessarily using Bash instead of sh?

Offline

#8 2015-09-05 10:50:51

twoion
Emerald Caffeine
From: 星界
Registered: 2012-05-11
Posts: 1,648

Re: Unnecessarily using Bash instead of sh?

It can make sense to use dash (or another simpler sh) instead of bash or definitely zsh when you spawn lots of shell instances that do nothing but to execute POSIX-compliant constructs like pipelines, or plain commands. It spawns faster because it's simply smaller with less context to set up.

Depending on how fast your computer is you might not notice a difference. I do, on a 2.7Ghz dualcore i5 laptop in 2015.

Offline

#9 2015-09-05 14:15:23

tknomanzr
#! Die Hard
From: Heavener, OK
Registered: 2014-12-09
Posts: 777

Re: Unnecessarily using Bash instead of sh?

Avoiding bashisms is important if you are trying to schedule cron jobs. That said, I generally just provide a wrapper script that does the trick for anything that I would end up needing to refactor the code to be sh compliant.

Offline

#10 2015-09-05 15:52:00

ostrołęk
CB Member
Registered: 2015-08-13
Posts: 110

Re: Unnecessarily using Bash instead of sh?

Offline

#11 2015-09-05 15:55:59

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: Unnecessarily using Bash instead of sh?

Offline

#12 2015-09-05 18:53:08

ostrołęk
CB Member
Registered: 2015-08-13
Posts: 110

Re: Unnecessarily using Bash instead of sh?

Offline

#13 2015-09-06 08:26:38

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: Unnecessarily using Bash instead of sh?

Offline

#14 2015-09-06 12:11:12

ostrołęk
CB Member
Registered: 2015-08-13
Posts: 110

Re: Unnecessarily using Bash instead of sh?

^ You are right in a way, by using #! /bin/sh, it doesn't matter, whether that sh files links to in a Linux system. In Debian/Ubuntu it'd invoke dash, while in other systems, it'd invoke bash. Whatever it is, the speed is undetectable in new computers. Mine is more than 4 years old, your places-pipemenu works the same way in Debian, Ubuntu or Arch.  smile

Offline

#15 2015-09-07 20:53:06

tknomanzr
#! Die Hard
From: Heavener, OK
Registered: 2014-12-09
Posts: 777

Re: Unnecessarily using Bash instead of sh?

The more I thought about this,  the more I thought that wrapping a bash script in a sh compliant script is technically really bad form. However, given my admittedly limited shell scripting abilities plus the fact that I am not likely to have more than a few scripts cron scheduled, it works for me.

I think what would happen in this case, is that the shell script would spawn a separate bash process to run the script. While this is ok on my own home brewed machine, it would probably be exceptionally bad form (if it were even allowed at all) to do on my web server host's machines, for instance.

Offline

#16 2015-09-08 02:44:19

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: Unnecessarily using Bash instead of sh?

AUTOSTART="${XDG_CONFIG_HOME:-"$HOME/.config"}/openbox/autostart"
# Run the user openbox autostart script
if test -f $AUTOSTART; then
    sh $AUTOSTART
elif test -f $AUTOSTART.sh; then
    sh $AUTOSTART.sh
fi

Offline

#17 2015-09-08 04:43:08

ostrołęk
CB Member
Registered: 2015-08-13
Posts: 110

Re: Unnecessarily using Bash instead of sh?

^ What you haven't pasted,

GLOBALAUTOSTART="/etc/xdg/openbox/autostart"
AUTOSTART="${XDG_CONFIG_HOME:-"$HOME/.config"}/openbox/autostart"

shows what is AUTOSTART, and it doesn't point to any file with an extension. Linux is an extension-less system so a script doesn't necessarily have to have this characteristic in order to work.
It could be either AUTOSTART or AUTOSTART.sh

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo