简体   繁体   中英

How to combine bash parameter expansion and command substitution?

I want to add a path to my PATH variable which includes the lowercase name of the OS. I can do the following now:

osname=$(uname -s)
osname=${osname,,}
export PATH="${HOME}/this/that/${osname}/bin"

Is there a way to write this on a single line, avoiding the variable itself?

如果可以避免,请不要尝试在 PATH 中嵌入执行。

declare -l osname="$(uname -s)" && export PATH="${HOME}/this/that/${osname}/bin";

This is the way

export PATH=$PATH:${HOME}/this/that/$(uname -s | tr '[:upper:]' '[:lower:]')/bin

I added $PATH at the beginning of the value since I guess you don't want to loose your actual $PATH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM