Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `set -x` do?

I have a shell script with the following line in it:

[ "$DEBUG" == 'true' ] && set -x 
like image 660
Ole Avatar asked Mar 29 '16 00:03

Ole


People also ask

What do set do?

set is a shell built-in that displays all shell variables, not only the environment ones, and also shell functions, which is what you are seeing at the end of the list.

What does set do in a script?

Set command: It is used to set or unset specific flags and settings( determines the behavior of the script and helps in executing the tasks without any issue.)

What does set do in terminal?

Typing 'set' just displays all of the shell variables and functions. set is used to set the variables and functions that are available and all you did was essentially asked to see what was currently set.

How does set work Bash?

In Bash, the set command allows you to manage certain flags and characteristics to influence how your bash scripts behave. These controls ensure that your scripts follow the correct path and that Bash's peculiar behavior does not cause difficulties.


1 Answers

set -x enables a mode of the shell where all executed commands are printed to the terminal. In your case it's clearly used for debugging, which is a typical use case for set -x: printing every command as it is executed may help you to visualize the control flow of the script if it is not functioning as expected.

set +x disables it.

like image 115
John Zwinck Avatar answered Oct 19 '22 20:10

John Zwinck