puritii
puritii

Reputation: 1289

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?

Upvotes: 0

Views: 234

Answers (2)

Paul Hodges
Paul Hodges

Reputation: 15246

Don't try to embed an execution in your PATH if you can avoid it.

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

Upvotes: 2

Francesco Gasparetto
Francesco Gasparetto

Reputation: 1963

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

Upvotes: 1

Related Questions