Bash is a utility to manage Linux and UNIX boxes and it is very popular because of its simple, well documented and unique usage. There are alternatives to bash like csh,sh,ksh but bash has very high usage rate against others. I have recently work on bash with its manual and wanted to write something that I have learned from them. By the way, bash is an acronym for “Bourne again shell”.
Bash是一种用于管理Linux和UNIX机器的实用程序,由于其简单,详细记录且独特的用法而非常受欢迎。 bash有其他替代方法,例如csh,sh,ksh,但bash与其他工具相比具有很高的使用率。 我最近在bash上使用了它的手册,并想写一些我从bash中学到的东西。 顺便说一句,bash是“ Bourne Again Shell”的首字母缩写。
Bash reads input and goes on a sequential manner. # is treated as comment line like this.
Bash读取输入并按顺序进行。 #像这样被当作注释行。
#Below is ping function to ismailbaydan.com
ping ismailbaydan.com # Ping the host
Here is what really bash make.
这才是真正的bash。
- Reads script from various sources like terminal, file, etc. 从终端,文件等各种来源读取脚本。
- Than parses the string in the input and makes required expansions and then gets commands. 比解析输入中的字符串并进行必要的扩展,然后获取命令。
- Performs necessary directions 执行必要的指示
- Executes commands and wait for the completion of the commands for their status.执行命令并等待命令完成以获取其状态。
As you can see there is a lot of work to execute a command or script in bash. But all of them makes the commands run in a perfect manner.
如您所见,在bash中执行命令或脚本有很多工作。 但是所有这些都使命令以完美的方式运行。
报价单 (Quoting)
Quoting is clearing special words and strings from the script and make them work correctly. A non-quoted backslash escapes character for the bash. Using single quote preserves characters in the string even usage of backslash but with double quoting makes $ ‘ \ special. For example, \t is a tab.
引用是从脚本中清除特殊的单词和字符串,并使它们正常工作。 bash的不带引号的反斜杠转义字符。 使用单引号即使使用反斜杠也可以保留字符串中的字符,但是使用双引号会使$'\特别。 例如,\ t是一个选项卡。
"İsmail Baydan\' website is \t ismailbaydan.com"
简单命令 (Simple Commands)
Generally, the line starts with commands and their arguments in bash and separated with blanks like this. Here ls
is the command and /home/ismailbaydan
is the argument. There may be a lot of arguments.
通常,该行以bash中的命令及其参数开头,并以空格分隔。 这里的ls
是命令,而/home/ismailbaydan
是参数。 可能有很多争论。
$ ls /home/ismailbaydan
流水线 (Pipelining)
The pipe is used to connect commands together. For example, to echo the content of the text file and look for a string is like this. grep uses the output of the cat command.
管道用于将命令连接在一起。 例如,回显文本文件的内容并查找字符串是这样的。 grep使用cat命令的输出。
$ cat phone_numbers.txt | grep Baydan İsmail Baydan 123456
定时 (Timing)
Timing is used to count CPU usage or time for a command. Here we make some copying and count for CPU usage.
计时用于计算命令的CPU使用率或时间。 在这里,我们进行一些复制并计算CPU使用率。
$ time dd count=100000 if=/dev/urandom of=/dev/null