Automating tasks with Shell Script is one of the most useful things a user or programmer should do.
It’s amazing how much time we spend daily doing things that a “robot” can do for us.
And having the environment as we wish is a small step for you, but a big step for your time savings.
We will now know 6 very interesting tips for the Shell that you can use not only on Linux, as the title says, but for any other system.
cat
command outputccat is the colorizing cat. It works similar to cat but displays content with syntax highlighting. Supported Languages: JavaScript, Java, Ruby, Python, Go, C, JSON and among others.
Another very interesting alternative is also the bat
command, which can be found at this link: https://github.com/sharkdp/bat
See an example of output from the bat command:
history
history
, just use an ‘exclamation sign’ !
and the command number, example: !480
, the shell will execute the corresponding number command.
Assuming you forgot sudo by running a command that needs it:
history
:For more informations, use:
PS1
variable)The first thing you see when you open the terminal is the command prompt, to better understand it, we can say that it is a “bar indicator” of your position in the Shell. Its appearance depends directly on the PS1 variable, which can be configured in the files: ~/.bashrc
, .profile
or any file that is part of the recursive tree.
You can customize with the colors you want and the information(metacharacters) you want, for example:
\u
- You enter the username of the shell;\h
- You enter the host name;\w
- The full path\W
- Current directoryFor example, run this in your terminal, if you like it add it to your ~/.bashrc
man
and making the reading more friendlyThe system manual is one of the parts most accessed by Shell, and many people do not like to use it very much, as they find it too technical saying that they cannot understand it well. Copy the command below and paste it at the end of your ~/.bashrc
and then open the manual and see the difference
shellcheck
Sometimes when we write our scripts/programs we encounter relevant syntax flaws, but they are still flaws.
For example, using the local declaration directly and already assigning a value to the variable will be identified as an error by ShellSheck. Therefore, you can obtain the fault number that ShellSheck will report and disable, as it is a workable fault:
The correct syntax without ShellSheck would be to declare the location first and then assign value to the variable _param
:
Do you want to know what such a command does? Then copy the LINE of the command and paste it into the search field on the website https://explainshell.com/ and get details about that command (s).
Thanks for reading!