Easily use the "Explain Shell" script to understand Shell commands

Source: Internet
Author: User

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.

  1. # apt-get install curl [On Debian systems]
  2. # 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.

  1. # explain.sh begins
  2. explain (){
  3. if["$#"-eq 0];then
  4. while read -p "Command: " cmd;do
  5. curl -Gs"https://www.mankier.com/api/explain/?cols="$(tput cols)--data-urlencode "q=$cmd"
  6. done
  7. echo "Bye!"
  8. elif["$#"-eq 1];then
  9. curl -Gs"https://www.mankier.com/api/explain/?cols="$(tput cols)--data-urlencode "q=$1"
  10. else
  11. echo "Usage"
  12. echo "explain interactive mode."
  13. echo "explain 'cmd -o | ...' one quoted command to explain it."
  14. fi
  15. }
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:

  1. $ explain 'du -h'

Get help for the du command

2. If you forget the role of 'tar-zxvf ', you can simply do this:

  1. $ 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.

  1. $ explain

Then enter the command one by one to see their respective functions in a window:

  1. Command: whatis
  2. 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.

  1. $ 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.