You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title says. Expanding variables in fallback values is standard POSIX behavior that's implemented in virtually all Linux shells (dash, bash, zsh, and many more I imagine). It is particularly useful for accessing XDG directories (my exact use case), e.g. "${XDG_DATA_HOME:-$HOME/.local/share}/". Would be great to have this.
expected output: /home/user/ actual output: $HOME/
Result with dash/bash/zsh
$ echo ${NON_EXISTENT_VAR:-$HOME}/
/home/user/
Technically this is recursive, i.e. echo ${ABC:-${DEF:-ghi}} in dash yields ghi if both $ABC and $DEF are undefined. But I understand that perfect POSIX-compliance might be too great an endeavor. IMO just a single-level expansion would be fine. Also an appropriate comment in the docs would be welcome.
The text was updated successfully, but these errors were encountered:
randoragon
added a commit
to randoragon/music-tools
that referenced
this issue
Feb 22, 2024
It turned out shellexpand has some limitations that bugged me
(netvl/shellexpand#22).
I opted to use the more low-level and popular "dirs" crate, which
allowed me to write a quite elegant abstraction in form of a new
path_from() function.
As the title says. Expanding variables in fallback values is standard POSIX behavior that's implemented in virtually all Linux shells (dash, bash, zsh, and many more I imagine). It is particularly useful for accessing XDG directories (my exact use case), e.g.
"${XDG_DATA_HOME:-$HOME/.local/share}/"
. Would be great to have this.Minimal reproducible example
expected output:
/home/user/
actual output:
$HOME/
Result with dash/bash/zsh
Technically this is recursive, i.e.
echo ${ABC:-${DEF:-ghi}}
in dash yieldsghi
if both$ABC
and$DEF
are undefined. But I understand that perfect POSIX-compliance might be too great an endeavor. IMO just a single-level expansion would be fine. Also an appropriate comment in the docs would be welcome.The text was updated successfully, but these errors were encountered: