So bash script options?
Query if Wayland is not running,
then start Plank at login.
Would probably use in a single command line in startup applications.
so if variable return confirms no wayland | PLANK
??
Any suggestions ?
So bash script options?
Query if Wayland is not running,
then start Plank at login.
Would probably use in a single command line in startup applications.
so if variable return confirms no wayland | PLANK
??
Any suggestions ?
This might help:
if [ "$XDG_SESSION_TYPE" = x11 ]; then
echo "Yep. X11"
else
echo "Nope. Not X11"
fi
If i’d riff off MarkofCain, I’m using this one:
DisplayType=${DISPLAY:+X11}${WAYLAND_DISPLAY:+WAYLAND}
if [[ $DisplayType == 'X11' ]]; then
echo "Yep. X11"
else
echo "Nope. Not X11"
fi
So if I wanted to reduce that to a single command to put in auto run of Gnome / KDE / Budgie
if [ “$XDG_SESSION_TYPE” = x11 ]; then &Plank
Should do it?
Or would I need to pipe the result using | ?
I just gave this a go on a Debian VM with my custom XFCE build and I ran into a few problems…
XDG_SESSION_TYPE
environment variable was set to tty
because I started XFCE from tty (because i’m a weirdo) so the if
statement wouldn’t workXDG_SESSION_TYPE=x11 plank
You also asked to only start plank
if it wasn’t running so I added a pidof
test.
This’d be the one-liner in POSIX:
[ "$XDG_SESSION_TYPE" = 'x11' ] && [ -z "$(pidof plank)" ] && plank &
If it doesn’t work for you (because of the forementioned), use this: (Wayland shouldn’t have a value for $DISPLAY)
[ -n "$DISPLAY" ] && [ -z "$(pidof plank)" ] && XDG_SESSION_TYPE=x11 plank &
So Debian uses Dash in place of Bash don’t they?
What is the difference?
Is there anything that Bash will do that Dash won’t?
Just wondering if commands should be tested under both shell environments?
The following is my opinion within the limits of my understanding…
The two most common shell languages are POSIX
script and BASH
. BASH script needs to be run by bash
(generally speaking) but POSIX script can be run in any shell that’s POSIX compliant. Fedora for example interprets POSIX script using bash
where Debian as you pointed out uses dash
.
Every *nix OS can run POSIX script and almost every *nix OS can run BASH. When you open a terminal or execute a script without a header, it’ll almost always be run in BASH unless #!/bin/sh
or #!/bin/dash
is at the top. Short answer is Debian has both.
As for speed and “better-ness”… this is where things get complicated…
dash
is extremely fast but it’s also extremely limited as a language so you almost immediately have to lean on spinning up GNU tools and other programs to fill in the gaps if you want to get anything done. While these tools are often written in C and VERY fast compared to BASH… if you need to use subshells $()
or do repeat quick operations it becomes extremely slow (sometimes by 10x to 20x by comparison) because of the overhead of having to launch the processes and interpretation of the arguments.
POSIX script can also make things harder to diagnose because it’s easy to end up in pipe hell and requires you know how to use a bunch of separate full featured programs all with their own unique quirks instead of one unified language of simple tools.
There’s a lot more to it… for example if you wanted the highest possible guarantee something with run everywhere then POSIX is the way to go but depending on what the script does it might require you add a ton of dependencies you wouldn’t need in BASH.
It’s good to use both and while most scripts run so fast it doesn’t mean anything to a human, sometimes there’s definitely a better one to use.
Good summary, I think !
Not being an expert in these things of course
Dude! Ingenious method of testing for truth and only moving forward when the conditions are satisfied. My quest for knowledge is done for the day.