DietPi-specific apps are not executing directly when using ZSH (and possibly any other shell)

Created on 27 Jan 2016  Â·  13Comments  Â·  Source: MichaIng/DietPi

Hello,

I'm using DietPi with ODROID-XU4, loving it so far! :smile:

I've a request, I hope this is considered.

I prefer using zsh[1] ( + oh-my-zsh ) over bash, however when I install it, DietPi-specific commands such as dietpi-config, cpu etc. are not executed. I had to dig the source code to find that they are actually /Dietpi/dietpi/dietpi-config, /Dietpi/dietpi/dietpi-update etc.

I would appreciate if these executables are also available when using zsh or any other shell without the need of using the whole path.

Thanks in advance,

Workaround available

Most helpful comment

@Ardakilic add this line at the bottom of .zshrc

/boot/dietpi/dietpi-login

2021 update for the latest commit

add this line at the top of .zshrc

export PATH=/usr/bin:/boot/dietpi:/bin:/usr/sbin:/sbin:$PATH

All 13 comments

@Ardakilic
DietPi uses bash alias to create the shortcut names. /etc/bash.bashrc

You will need to ensure zsh loads/applies the bash aliases when connecting. I'am unsure as I've never used zsh before.

You could also run /DietPi/dietpi/dietpi-launcher which executes the full filepath of your selected DietPi script/program.

@Fourdee I've tried sourcing it manually but it breaks another stuff of oh-my-zsh:

➜  ~  source /etc/bash.bashrc
/etc/bash.bashrc:11: command not found: shopt
\u@\h:\w$ ls  # <- see, the arrow is now weird characters.

Since you've put it in the proper paths I'll be closing this and try to fix it in the zsh's end.

Thank you again,

@Ardakilic add this line at the bottom of .zshrc

/boot/dietpi/dietpi-login

2021 update for the latest commit

add this line at the top of .zshrc

export PATH=/usr/bin:/boot/dietpi:/bin:/usr/sbin:/sbin:$PATH

FYI if you uninstall oh-my-zsh and go back to bash you can avoid this issue.

The problem is indeed that official support means that DietPi-Globals would need to be proven zsh compatible, and this required quite some testing or a detailed study of bash vs zsh differences which I do not find time for currently.

Ref: https://unix.stackexchange.com/questions/38172/are-all-bash-scripts-compatible-with-zsh
There are some syntax differences indeed which makes cross-compatibility an additional effort.

If I use the solution by @msongz it works 4 me. (I only tried dietpi-update :D )
Would it be possible to leave this ticket open and add scripts that make trouble (that are not zsh compatible)?

@FWeissenb
Yes the aliases will work, that's true. As well all our scripts will work, since the have a bash shebang, so will always run in bash, even if called from zsh shell.

The issue is all the other functions and inits that are done within: https://github.com/MichaIng/DietPi/blob/dev/dietpi/func/dietpi-globals
Especially that arrays start with index 1 in zsh instead of index 0 makes it incompatible, other minor flows due to missing ${var^} ${var,} support and probably more critical the much larger palette of file expansion syntax makes it even dangerous, e.g. we use a string that have no special meaning in bash and are involved in a removal or move task, and in zsh suddenly it has a syntax meaning and is expanded to a local file that is then removed or overwritten.

The only viable solution I can think of is to create a zsh-only login script, e.g. /etc/zshrc.d/dietpi.zsh should work, and then add only safe features, like the aliases and the dietpi-login script+banner (which are external scripts called as bash) to autologin/start and such. Further parts/features can be added as needed, like the G_AG* command set, when carefully checked or made zsh compatible, at a later time.

@Ardakilic add this 2 lines at the bottom of .zshrc

/DietPi/dietpi/login
. /DietPi/dietpi/func/dietpi-globals

add this line at the top of .zshrc

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH

Actually now instead of having /DietPi/dietpi/login you have to have /DietPi/dietpi/dietpi-login.

Sorry for replying to a closed thread but i thought this might help, it seems to be working on my system (raspberry pi 4) as expected.

I would suggest adding a feature in dietpi-software that would allow the user to migrate between default shells and setup would be automatic, it doesn't seem that complicated and i would imagine most new users would rather use zsh or fish instead of bash.

Here's an image depicting the auto completion in zsh showing all dietpi related software:
image

@JPUnD
The issue is still present, that bash and zsh (and others) are not 100% compatible when it comes to scripting. And dietpi-globals includes quite a lot of code where e.g. wrong array index counting and others result in bugs and visual flakes at best.

But I have the idea to separate things a bid:

  • dietpi-login and the program aliases do not require dietpi-globals, hence those can be loaded regardless of shell.
  • The few environment checks we do, can be made cross-compatible easily.
  • dietpi-globals would then only be loaded on bash for now, which includes G_* functions and variables, which I assume are rarely used directly by users anyway,

Only question I have is if zsh allows to add custom system-wide scripts via e.g. /etc/zshrc.d/myscript.sh?

@MichaIng

I have no idea how most of these things work, all i did was use that guy solution and changed it's path. If all the scripts have the correct shebang then they still will be run with bash, so having zsh should have no effect on the output or syntax of the script.

I have no idea if zsh allows custom system-wide scripts, but i've added custom paths before to zsh and calling the scripts worked as expected.

@JPUnD

If all the scripts have the correct shebang then they still will be run with bash

That is not true. /etc/bashrc.d/dietpi.bash is not "executed" but "sourced", the same as zprofile, zshrc etc by the zsh shell. This means that it is parsed like if you would type those commands right into your zsh session (regardless of shebang). And it again sources /DietPi/dietpi/func/dietpi-globals (leading dot .), which is hence as well parsed in zsh. /DietPi/dietpi/login and all the aliases dietpi-software, dietpi-config etc are executed, hence for those it is true that the originating shell does not matter.

@MichaIng

Ah alright then, but so far i've been using the scripts with zsh in my RPI4 and haven't encountered any issue yet.

@JPUnD
Jep as said, as long as you don't use G_* commands from command line, everything else should well. It is a fine workaround, but there above separations are required to not add buggy/failing G_* functions to zsh shells.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kapot picture Kapot  Â·  3Comments

Fourdee picture Fourdee  Â·  3Comments

bhaveshgohel picture bhaveshgohel  Â·  3Comments

mok-liee picture mok-liee  Â·  3Comments

k-plan picture k-plan  Â·  3Comments