Displaying Shell Expansion Introduction

If a command is entered in the command line, it expands into its output which is displayed. This is called expansion.


If a command you are typing will be printed with the help of echo command on the terminal. This command will be useful when you want to check what your command is doing in the shell. Shell is the place of command working.

 Command        Function
 set -x         Used to enable shell expansion.
 set +x         Used to disable shell expansion.
 set -x         command enables shell command display.

Sample syntax of shell echo :

# echo <text>  

Like example of :

# echo $USER  
# echo \$USER  

See your terminal after run this command, ‘set -x’ displays shell expansion in the terminal.

You can see what the shell is doing with the given command. With command “echo $USER” shell expansion shows that $USER is convert to ‘student’.

The echo \$USER shell expansion shows that due to special character backslash () $USER is not convert to ‘student’.

set +x

‘set +x’ command disables shell command display.

Sample syntax of :

# echo <text>  

Like example of :

# echo $USER  
# echo \$USER  

See your terminal after run the command, shell expansion is disable and hence, output is directly print in the terminal.

Linux Control Operators

Linux control operators you can put more than one command in the command line. It helps in performing a control function of your system.

Use of control operators

The Linux command ( \ ) backslash enables control character but without shell interpretation.

Control Operator Usage
; semicolon One command can be use in a single line.

& ampersand It is ends with & and doesn’t wait for command to finish.

$? dollar and question mark It is use to store exit code of the previous command.

&& double ampersand Used as logical AND.

|| double vertical bar Used as logical OR.

Combining && and || Used to write if then else structure in command line.

# pound sign It is anything written after will be ignore.

\ escaping special characters

Linux shell very often involve repeating yourself. It working with sets or ranges of information.

If you clearly this shell expansion, I hope it can be help you many time. Now you can practice your own ability. Thank you.