MLUG Bash Scripting Workshop 25/04/08 | ||
---|---|---|
Prev | Index | Next |
I don't want to get bogged down in too much detail. There are lots of things on the net if you want to become an expert.
For this workshop it is only necessary for you to understand that Bash is doing the work for you. It is running the commands when you type them in then hit enter. It will run commands one after another from a text file you have created and it will do other neat things like take the output from one command and feed it into a second command and so on.
For example, if I run the command "ls -l | grep Bash" in my home directory, the output from "ls -l" is "piped" to the command "grep Bash" which will only print (to screen) any files or directories containing the word Bash:
rick@rick:~$ ls -l | grep Bash drwxrwxrwx 5 rick users 576 2006-03-30 07:21 Bash_Scripting/
If I ran the command "ls -l | grep Bash > example.txt" the output from "grep Bash would not print (to screen) because the output has been redirected to a file named "example.txt" instead.
rick@rick:~$ ls -l example.txt /bin/ls: cannot access example.txt: No such file or directory rick@rick:~$ ls -l | grep Bash > example.txt rick@rick:~$ ls -l example.txt -rw-r--r-- 1 rick users 67 2008-04-13 14:49 example.txt rick@rick:~$
I could go on like this for a long time. Suffice to say that Bash is interpreting the user input and running the binary executables "ls" and "grep". It is also managing the output of those commands using two of its own features "piping" and "redirection".