0

I know the typical way is echo "$PATH", for example. But echo $PATH also works. Also, you don't need the echo command even, you can just type $PATH, and the value of path will be outputted to the screen.

What is the difference in these, and is there any preference for a particular command and why?

vw1262
  • 11
  • 1
    "you can just type $PATH, and the value of path will be outputted to the screen."? Usually it comes in the form of an error message, no? What shell are you using and what's the actual output you get? What do you think that actually does? What if the you had e.g. `var=ls` and then ran just `$var`? – ilkkachu Jul 15 '23 at 17:50
  • as for the double quotes, see the mandatory FAQs: [When is double-quoting necessary?](https://unix.stackexchange.com/questions/68694/when-is-double-quoting-necessary) and [Why does my shell script choke on whitespace or other special characters?](https://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters) and https://mywiki.wooledge.org/WordSplitting – ilkkachu Jul 15 '23 at 17:51
  • In Bash, also `declare -p PATH`. There is no distinction between printing normal user variables and environment variables. – Paul_Pedant Jul 15 '23 at 22:34

1 Answers1

-1

With quotation marks around the variable, you prevent globbing and word splitting see shell check

Grigorios
  • 151
  • 10