Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell command SET -X mean in script [duplicate]

Tags:

bash

sh

So I have a file deploy.sh, and it has the shell script. Since I know about it, I have a little confusion, that is what does that set -x actually means.

After running the file I have observed that the command written after it in the file gets mentioned in the terminal with a + sign.

Like if I have this,

#!/bin/bash
set -x

ng build

So the output mentions +ng build, and when I comment the set -x from the file, everything executes, but the later commands does not show up in the terminal.

I have researched about it, but specifically couldn't find the real meaning and work of this particular command.

like image 367
Alok Avatar asked Oct 05 '18 10:10

Alok


People also ask

What does set mean in shell script?

The set command is a built-in Linux shell command that displays and sets the names and values of shell and Linux environment variables. On Unix-like operating systems, the set command functions within the Bourne shell ( sh ), C shell ( csh ), and Korn shell ( ksh ).

What is $1 and $2 in shell script?

These are positional arguments of the script. Executing ./script.sh Hello World. Will make $0 = ./script.sh $1 = Hello $2 = World. Note. If you execute ./script.sh , $0 will give output ./script.sh but if you execute it with bash script.sh it will give output script.sh .

What is $? 0 in shell script?

After a script terminates, a $? from the command-line gives the exit status of the script, that is, the last command executed in the script, which is, by convention, 0 on success or an integer in the range 1 - 255 on error. Example 6-1. exit / exit status. #!/bin/bash echo hello echo $?

What is if $? 0 ]; then?

$? is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. That line is testing whether the grep command succeeded.


1 Answers

You can read the bash online manual for set:

-x

Print a trace of simple commands, for commands, case commands, select commands, and arithmetic for commands and their arguments or associated word lists after they are expanded and before they are executed. The value of the PS4 variable is expanded and the resultant value is printed before the command and its expanded arguments.

So it does exactly what you described.

like image 86
Würgspaß Avatar answered Sep 30 '22 13:09

Würgspaß