Skip to main content
the "explanation" header is taller than the entire explanation
Source Link
muru
  • 78.4k
  • 16
  • 214
  • 321

If you want it to work without sudo as well, use ${SUDO_USER:-$USER}. For example:

printf '%s\n' "${SUDO_USER:-$USER}" 

Explanation

${var:-val} will expand to $var, unless it's unset or empty, in which case it will expand to val.

If you want it to work without sudo as well, use ${SUDO_USER:-$USER}. For example:

printf '%s\n' "${SUDO_USER:-$USER}" 

Explanation

${var:-val} will expand to $var, unless it's unset or empty, in which case it will expand to val.

If you want it to work without sudo as well, use ${SUDO_USER:-$USER}. For example:

printf '%s\n' "${SUDO_USER:-$USER}" 

${var:-val} will expand to $var, unless it's unset or empty, in which case it will expand to val.

add explanation
Source Link
user3730
user3730

If you want it to work without sudo as well, use ${SUDO_USER:-$USER}. For example:

printf '%s\n' "${SUDO_USER:-$USER}" 

Explanation

${var:-val} will expand to $var, unless it's unset or empty, in which case it will expand to val.

If you want it to work without sudo as well:

printf '%s\n' "${SUDO_USER:-$USER}" 

If you want it to work without sudo as well, use ${SUDO_USER:-$USER}. For example:

printf '%s\n' "${SUDO_USER:-$USER}" 

Explanation

${var:-val} will expand to $var, unless it's unset or empty, in which case it will expand to val.

Source Link
user3730
user3730

If you want it to work without sudo as well:

printf '%s\n' "${SUDO_USER:-$USER}"