[Ilugc] [TIP] some shell ideas

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Wed, 21 Dec 2011 05:44:35 +0530

Shell scripting is not just programming.

It is a bunch of things that one knows to do effective work
 from the command line.

One can do good shell scripting only after a rich UNIX experience
 which takes some 4 years.

You need to know all the fancy UNIX command line tools which you
can invoke from a script or even directly from the shell.

Before you proceed to shell scripting per se you can just play
 with the shell to get some basic facilities byheart that help you
  with day to day tasks.

For example,

$ history

will give you list of commands executed previously.

Bash will give you history from the last login session. ksh will not.

But nobody uses this command these days.

Just press the up arrow and you can cycle thro' all the commands.

Also <TAB> completion is nice.

Just type the first letter or first two letters of a command or file name
 and press the <TAB> key. It will complete the rest of the command for you.

You can look at the shell environment with the set command.

$ set

You can find out certain basic things like

$ echo $HOME

$ echo $USER

$ echo $SHELL

You can set the prompt with

$ export PS1=foo>

You can find these silly things in any book on UNIX.

You can do line editing with:

Ctrl-a to go to beginning of line

Ctrl-e to go to end of line

Ctrl-K to kill the line

Ctrl-r will do a reverse search on command history

Remember certain things.

Shell variables do not actually get exported to the child shells till you
actually export them.

Every shell script starts a new shell which is the child of the parent
shell where
 you type commands.

So you have to export variables to make the variables show up in child shells
as well.

You also have functions in shell scripting.

$ function foo {

 echo "how are you?"
}
$ foo
how are you?

The '>' and '$' was not typed by me.

-Girish

-- 
G3 Tech
Networking appliance company
web: http://g3tech.in ?mail: girish at g3tech.in

Other related posts:

  • » [Ilugc] [TIP] some shell ideas - Girish Venkatachalam