Sometimes when I run commands it doesn't display an output, so I'm not sure if they've worked or not. Is it possible to make all commands have feedback if they've ran correctly or not? Or at the bare minimum to display feedback id they've ran (correcly or not)
There is a very good answer in Stack Overflow question In a shell script: echo shell commands as they are executed (this is not just a Ubuntu-specific solution).
What you need to do is use the set command to turn verbose or xtrace on.
will give you a list of which current parameters are switched to on or off.
or the longform version:
will turn verbose ON.
I think what you want, though, is actually xtrace. This will not only echo every command you run, it will also expand the parameters and give you more feedback. So if I do something as silly as typing 'hi' at the terminal, I will get the echo of what I typed as well as a report/trace of what the shell did to attempt to execute the command 'hi' (see screenshot below):
To enable xtrace:
To disable these parameters, you (counter-intuitively) call the same commands except with a plus symbol + instead of a dash or minus symbol, so, for example:
will turn verbose OFF, similarly:
will turn xtrace OFF.
A detailed guide on shell options is in Chapter 33. Options, Advanced Bash-Scripting Guide.
To check if some command worked successfully or not you can check the return status, given by
A return status of
Also in bash, the
You can append the following line of code to your
(open the file
a little demo:
Just playing with
(you can modify the function to make it more fancy, something like @gronostaj does in his post.)
You can change your command prompt to display a green tick sign when previous command exits with 0 and red X otherwise. Arch Linux Wiki has some nice piece of code to add to your
(I have disabled the actual error code because I don't like it, if you'd like to see exact codes just remove
Here's how it looks:
Yes, it's possible to get feedback for every command you executed on the terminal.It works on the basis of
To get the success or failure feedback, add the below line to
And then source
For every command you executed on the terminal, this