Home » Linux Displaying Shell Expansion

Linux Displaying Shell Expansion

by Online Tutorials Library

Displaying Shell Expansion

When a command is entered in the command line, it expands into its output which is displayed.

This is called expansion.

The command you’re 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.

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

set -x

The ‘set -x’ command enables shell command display.

Syntax:

Example:

Linux Shell Expansion Displaying1

Look at the above snapshot, ‘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 converted to ‘sssit’.

With command “echo $USER” shell expansion shows that due to special character backslash () $USER is not converted to ‘sssit’.

set +x

The ‘set +x’ command disables shell command display.

Syntax:

Example:

Linux Shell Expansion Displaying2

Look at the above snapshot, shell expansion is disabled and hence, output is directly printed in the terminal.

You may also like