|
|
Penguins Unbound > Past Meetings > 20110730 - Bash Programming > Shell Scripting (or old *nix tools) > 01 - Shell Basics
01 - Shell BasicsTable of contentsGetting started.
There no "right" way, there are some better solutions and worse but there are many ways to get the job done.
The shell uses both built-in commands, that are programmed into the shell program, and then other commands in the path. If you want to be sure that you use a program on the system you may need to specify the whole path to the program.
I/O Redirection and PipesThe shell uses different "streams" for input and output. There are 3 default streams I/O, and they are numbered 0 standard input 1 standard output 2 standard error You can redirect this output to a number of different places.
If you want to discard the output from a command you can pipe the output to dev null (the system bit bucket) ls -al > /dev/null
ls -al /usr/bin | more That will take the output from ls -al and pipe it into more so it will be paged and you ahd look through the output.
You can also capture output of a command in a variable with THE_VARIABLE=`date +%Y%m%d`
Control and ExectionFor While Case If
VariablesShell ariables are simple to work with. You simply set a variable with The_Shell_Variable="This"
You can print or echo a shell variables with echo "The Shell Variable is ${The_Shell_Varible}"
There are several predefined variables for use. PS1 - your pompt USERNAME - your user name HOME - your home directory UID - your user id number
Shell enviornmentThese commands display the enviornment env set Different shell variables can effect how the shell and program act. |