Many systems include shell inbuilt man pages, however, these are only valid if you’ve used the standard shell. We possess POSIX control man pages, which would show up for terminal builtins since there isn’t a freestanding tool to shadow them; those man pages seem valid across all Bourne-style terminals but seem to be frequently inadequate. The solution is the same across Bourne-style shelling in this situation. Let’s have a look at the man page of the set.
Before that, log in from the Linux operating system and try to open the console application through the app area. If you want to do it quickly, just try “ Ctrl+Alt+T”. When the console shell got opened, open the man page using the help instruction command within the shell as below:
You will get a lot of information regarding the set feature and its usage. Let’s scroll a little below to find out about set –x more. You can see that it says this could print commands and their arguments as they are executed.
Set -x operates across both collaborative and non-interactive environments, so test it in a dynamic terminal to see just what happens. Each statement is initially repeated back to the user. Let’s have a look at “set –x”, but within it, we will also have a look at the “set +x” option after some time. So first of all, we need to execute the set –x option in the shell as per the below snapshot. The output shows that the “set –x” has been set and it will let you know that it has to print the lines of code as it is as they are implemented.
Let’s have a look at the basic code of bash to implement the set –x on our system. First of all, we will be implementing the one-line code to check the change of set –x on it. So, we have used the simple “echo” statement in the shell. Make sure not to use double inverted commas for the covering of an echo message. Because it will not be going to work the way we want it. The output shows the repetition of an echo statement in the shell as it is first with the plus sign. After that, we have seen how it also displayed the message of the echo statement in the shell as per the execution of the “echo” statement.
Let’s see some more lines of codes to get a glance at “set –x” in bash within Ubuntu 20.04 system. First of all, we have added the bash extension within the shell command line area and hit “Enter”.
After that, we have declared a simple variable named “val” and assigned it a string-type value “Aqsa”. After that, we have again tapped the “Enter” button from the keyboard.$ val=“Aqsa”
After the initialization or declaration of a variable, we wanted to print it in our terminal using the “echo” instruction. You will see it will print the value of variable “val” as Aqsa” in the output area. Right now, we have not applied the settings option on the code, that’s why it simply displays the value of the variable, and nothing changes. This was the simple code to do, without a set option.
Let’s set the “set +x” option and see what changes. For that simply try the below command:
We have declared a variable named “age” in the shell having integer type value “25”. When we have used the echo statement to display the value of the variable “age”, it simply displays it with no change. Hence, this proves that “set +x” always works as opposed to “set –x”.
$ echo $age
Let’s set the “set –x” option and have new lines of code on the terminal.
So we have tried the below query to set the “-x” option:
Now the option has been set, it’s time to declare some variables first. So, we have declared a variable named “job” in the shell. Then, we have assigned it a string type value “writer”. When we have pressed “enter”, it displays the same line of instruction at the output area, with the plus sign as per the image below.
When we tried the echo statement to show the value of the “job” variable, it does not only shows what echo statement is going to print, e.g., value “writer” of variable “job” with a plus mark but also displays its value at the next line separately.
Let see how it works with the echo statement when more than two variables are used within it with a “+” mark for concatenation of strings. Hence, we have used the below instruction to concatenate two string-type variables. At the first line of output, it displays what is going to be the output, and the second line of output simply executed the result of the “echo” phrase.
After this, we have used the same style of concatenation for string and integer type of variable. It outputs the same way as it does above.
To apply set –x on some mathematical expressions, let’s first see a simple echo statement on an expression of integers as below. Make sure to use the required commas instead of double. It simply displays the sum of both integers.
Now set –x option, and then run the above expression once again. You will see that it will show you the steps it takes to evaluate the expression. Firstly print the evaluation of expression within the echo line. After that, it will show the echo statement with the expression evaluated. The last line will show the result.
$ echo `expr 12 + 17`
When you set +x, it will reverse the process as below:
$ echo `expr 12 + 17`
The above discussion shows that when set -LETTER enables a possibility, set +LETTER disables it. As a result, setting +x disables traces. The set +x trace is inevitable unless you quit the shell — in which case you would use a subshell.