Learn GNU/Linux Commands (2): Variable - echo, $PATH, $HOME, $PWD

Before introducing other commands, let's find out what GNU/Linux commands really are.

We have talked about directory and pathname in Part 1.

Each command like cd, pwd, ls that we talked about in Part 1 is actually a relative pathname to an executable binary file. Because the pathnames of these executable binary files' parent directory are stored in the variable PATH, we can directly call the file names as commands anywhere in the shell.


Variable

A Shell variable is a placeholder of a string of characters. strings of characters are called strings in many programming languages. In other words, when commands that contain variables are executed, these variables are replaced with the strings they represent.

Variables can be named with alphabetic characters, numbers and "_", but variable names can not starts with a number and are usually in lowercase.

There are a set of predefined variables called environment variables, which can affect the behavior of running processes. Environment variable names are usually in uppercase. We will introduce environment variable PATH, PWD, HOME later.

to assign a variable:

variable=value
if what we need is the value, we add a "$" before the variable as $varialbe.


Display string(s)

echo [string]

echo(print/display) the string(s).

[Texpion@com ~]$ echo "Hello, world"
Hello, world

Note: for this command, quotes are not required, but if strings are not quoted, continuous whitespaces will be treated as one " ".

[Texpion@com ~]$ echo Hello,     world
Hello, world

PATH

PATH is an environment variable that stores the pathnames of parent directories of executable binary files.

Let's echo PATH.

[Texpion@com ~]$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
We had mentioned what variables are. If we echo a variable, the string it represents will be displayed.

For $PATH, pathnames of each directory are separated with ":". Executable (command) files can be found under directories named "bin", Executable (command) files for superusers can be found under directories named "sbin".


HOME

HOME is an environment variable that stores the home directory('s pathname).

Let's echo HOME:

[Texpion@com ~]$ echo $HOME
/home/texpion


PWD

PWD is an environment variable that stores the working (current) directory('s pathname).

Let's echo PWD:

[Texpion@com bin]$ echo $PWD
/usr/local/bin
The working (current) directory's pathname can also be displayed with the command "pwd" mentioned in PART 1.



Related

Comments

Popular

Intel 7th and 8th generation processor graphics driver for Windows 7/8/8.1

AV1 vs VP9 vs AVC (h.264) vs HEVC (h.265): Part II - Fidelity

AV1 vs VP9 vs AVC (h.264) vs HEVC (h.265): Part I - Lossless

AV1 vs VP9 vs AVC (h.264) vs HEVC (h.265): Part IV - Decode

AV1 vs VP9 vs AVC (h.264) vs HEVC (h.265): Part III - Quality

OBS Studio settings for best quality (loseless) recording

Install VMAF on Fedora, CentOS/Red Hat (RHEL)