Bash Command Basics
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 is 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 reads input and go on sequential manner. # is treated as comment line like this.
#Below is ping function to ismailbaydan.com</code> <code>ping ismailbaydan.com # Ping the host
Here is what really bash make.
- Reads script from various sources like terminal, file etc.
- Than parses the string in the input and makes required expansions and than gets commands.
- Performs necessary directions
- Executes commands and wait for 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.
Quoting is clearing special words and strings from the script and make them work correctly. A non-quoted backslash is escape character for 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.
"İsmail Baydan\' website is \t ismailbaydan.com"
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.
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.
$ cat phone_numbers.txt | grep Baydan İsmail Baydan 123456
Timing is used to count CPU usage or time for a command. Here we make some copying and count for CPU usage.
$ time dd count=100000 if=/dev/urandom of=/dev/null