Is it possible to combine two or more string manipulation functionalities of a variable in BASH (or any other standard Linux command)?
Let's say e.g. I have the variable $XDG_CURRENT_DESKTOP
which holds the string ubuntu:GNOME
.
Now, I can retrieve the second substring by ${XDG_CURRENT_DESKTOP##*:}
→ GNOME
.
I can also retrieve the lower case string through ${XDG_CURRENT_DESKTOP,,}
→ ubuntu:gnome
.
But how can I combine both functions (→ gnome
) in one – simple – command without using a redirection to sed
, awk
, grep
or any other of these – quite heavy weighted – commands and without an additional buffer storage step? e.g.:
local mybuffer="${XDG_CURRENT_DESKTOP##*:}"
echo "${mybuffer,,}"
I want to avoid such a "sub-script" or function call construct to achieve this and I already tried any combination of both mentioned but it seems to be futile.
Is there any other way?
Or do I need to upgrade bash? (using: GNU bash 4.3.11)
Or can any other shell do that?
zsh
can do it, with theL
parameter expansion flag ex.${(L)XDG_CURRENT_DESKTOP##*:}
zsh
. Thank you very much! :))