The $PATH
shell variable is a list of directories that the shell searches for executables when you run a command. To read or print the $PATH
variable, you can use the echo
command and the $PATH
variable.
Here is an example of how to print the $PATH
variable in the Bash shell:
echo $PATHSocrue:www.lautturi.com
This will print the $PATH
variable to the terminal, with the directories separated by a colon (:
). For example:
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
You can also use the echo
command to print specific directories in the $PATH
variable. For example, to print only the first directory in the $PATH
variable, you can use the cut
command to split the $PATH
variable and print the first field:
echo $PATH | cut -d: -f1
This will print the first directory in the $PATH
variable, for example:
/usr/local/bin