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 output
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:
02. Customizing Shell
- By default, the history command displays only the command order number and the command used. To also display the date of the command’s execution, you can change its behavior only with this line:
- To execute a command from
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:
- Cleaning all
For more informations, use:
03. Customizing the appearance of your command prompt (
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:
.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 directory
For example, run this in your terminal, if you like it add it to your
04. Coloring the
man and making the reading more friendly
The 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
05. Look for bugs in your Shell Code with
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
06. Get Explanations of Shell Commands
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!