Easily use the "Explain Shell" script to understand Shell commands
When we work on Linux, everyone will find the help information of shell commands. Although built-in help such as man pages And whatis commands are helpful, the output of man pages is very lengthy unless it is a person with Linux experience, otherwise, it is very difficult to obtain help information from a large number of man pages, and the output of the whatis command rarely exceeds one line, which is not enough for beginners.
Explain Shell commands in Linux Shell
There are some third-party applications, such as the 'cheat' command we mentioned in the command line speed table of Linux users. Cheat is an excellent application that provides shell commands even if the computer is not connected to the Internet, but it is limited to pre-defined commands.
Jackson wrote a short piece of code, which can effectively explain shell commands in bash shell. The most beautiful thing is that you do not need to install third-party packages. He named the file containing this code as "explain. sh ".
Features of the explain. sh Tool
- Easy to embed code.
- Third-party tools are not required.
- Output the right information during the interpretation process.
- Network connection is required to work.
- Command line tool.
- It can explain most shell commands in bash shell.
- You do not need to use the root account.
Prerequisites
The only condition is the 'curl' package. Currently, curl packages have been pre-installed in most Linux distributions. If not, run the following command to install the packages.
# apt-get install curl [On Debian systems]
# yum install curl [On CentOS systems]
Install the explain. sh tool on Linux
We want to insert the following code '~ /. Bashrc. We want to insert this code for each user and the corresponding '. bashrc' file, but we recommend that you do not add it to the root user.
We noticed that the first line of code in the. bashrc file starts with (#). This is optional and only serves to differentiate the remaining code.
# Explain. sh mark the beginning of the Code. we insert the code to the bottom of the. bashrc file.
# explain.sh begins
explain (){
if["$#"-eq 0];then
while read -p "Command: " cmd;do
curl -Gs"https://www.mankier.com/api/explain/?cols="$(tput cols)--data-urlencode "q=$cmd"
done
echo "Bye!"
elif["$#"-eq 1];then
curl -Gs"https://www.mankier.com/api/explain/?cols="$(tput cols)--data-urlencode "q=$1"
else
echo "Usage"
echo "explain interactive mode."
echo "explain 'cmd -o | ...' one quoted command to explain it."
fi
}
Use of the explain. sh Tool
After the code is inserted and saved, you must exit the current session and log on again to make the change take effect.source~/.bashrc
). Everything is handled by the 'curl' command. It is responsible for transmitting the commands and command options to the mankier service and then printing the necessary information to the Linux Command Line. Needless to say, you always need to connect to the network to use this tool.
Let's use the explain. sh script to test several command examples that I don't understand.
1. I forgot what 'du-H' is for. I just need to do this:
$ explain 'du -h'
Get help for the du command
2. If you forget the role of 'tar-zxvf ', you can simply do this:
$ explain 'tar -zxvf'
Tar command help
3. A friend of mine is often confused about the use of the 'whatis 'and 'whereis' commands, so I suggest him:
Simply tap the explain command on the terminal to enter the interaction mode.
$ explain
Then enter the command one by one to see their respective functions in a window:
Command: whatis
Command: whereis
Whatis/Whereis Command help
You only need to use "Ctrl + c" to exit the interaction mode.
4. You can request and explain more commands through pipelines.
$ explain 'ls -l | grep -i Desktop'
Get help for multiple commands
Similarly, you can request your shell to explain any shell command. The premise is that you need an available network. The output information is generated from the server based on the command to be interpreted. Therefore, the output result cannot be customized.
This tool is really useful for me and has been honored to be added to my. bashrc file. What do you think about this project? Does it work for you? Are you satisfied with its explanation? Please let me know!
Please comment below to provide us with valuable comments, like and share with us and help us spread.
Via: Understanding Shell Commands Easily Using "Explain Shell" Script in Linux
Author: Avishek Kumar Translator: dingdongnigetou Proofreader: wxy
This article was originally translated by LCTT and launched with the Linux honor in China
This article permanently updates the link address: