0

I am reading nvm shell script and meet something I don’t understand, please help

nvm_profile_is_bash_or_zsh() {
  local TEST_PROFILE
  TEST_PROFILE="${1-}"
  case "${TEST_PROFILE-}" in
    *"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
      return
    ;;
    *)
      return 1
    ;;
  esac
}

What is the role of symbols - in line TEST_PROFILE="${1-}" and ${TEST_PROFILE-}?

  • See also [parameter expansion](https://wiki.bash-hackers.org/syntax/pe). – Charles Duffy Apr 30 '21 at 14:26
  • BTW, all-caps names are used for variables that can change behavior of the shell or other POSIX-specified commands, whereas the POSIX sh standard reserves variables with at least one lower-case character for application use and guarantees that they won't have unintended effects on the shell's behavior. (That guarantee only holds for POSIX-compliant shells, though, so zsh doesn't honor it). – Charles Duffy Apr 30 '21 at 14:28
  • ...on that convention, see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html, keeping in mind that environment variables and regular shell variables share a single namespace (modifying a shell variable will overwrite any like-named environment variable). – Charles Duffy Apr 30 '21 at 14:29

0 Answers0