Fundamentals 3 min read

Shell Custom Variables: Definition, Format, Types, and Usage

This article explains what shell variables are, their naming rules and assignment syntax, the different categories of variables, and demonstrates how to define and output custom variables in Linux shells with practical command‑line examples.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Shell Custom Variables: Definition, Format, Types, and Usage

Variable definition: a variable is a storage space that can hold a mutable value, which can be changed in different environments. By default, each shell in Linux can be seen as a separate execution environment, so the same variable name may have different values in different shells.

1.1 Variable format

VariableName = VariableValue

Variable names cannot start with a digit or special character.

"=" is used for assignment.

Variable values can be numbers, strings, file paths, commands, or command results.

1.2 Classification of shell variables

Custom variables, environment variables, positional variables, predefined variables.

1.3 Variable output

a=1
echo $a

echo outputs the variable; note the $ prefix before the variable name.

-----------------------------------------------------------------

2. Custom variables

Example 1:

[root@node1 ~]# Linux=7.2
[root@node1 ~]# echo $Linux
7.2
[root@node1 ~]# linux=6.5
[root@node1 ~]# echo $linux
6.5
[root@node1 ~]# echo $Linux
7.2

Conclusion: there must be a space between echo and the variable, and variable values are case‑sensitive.

Example 2: invoking multiple variables

[root@node1 ~]# system=centos
[root@node1 ~]# version=7.2
[root@node1 ~]# echo $system $version
centos 7.2
[root@node1 ~]# echo sys{$Linux}
sys{7.2}
[root@node1 ~]# echo sys$Linux
sys7.2

Conclusion: you can directly echo the variable name.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxShellcommand-lineScriptingVariables
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.