bash quick start

Sachverstand2 @ Geocities.com

started on 04.09.1998 - updated on 04.09.1998

Index

What is bash, anyway?

How do I start bash?

Options and Parameters

Piping input and output

Foregrounding, Backgrounding, and Killing of processes

Writing shell scripts


Go back to Main Index . . . Go back to Linux User's Help Page

1 What is bash, anyway?

bash is a shell, that means a program that sits in between you and Linux.
bash lets you invoke and control processes on the system.

2 How do I start bash?

When you log in, a session of bash is automatically opened for you, to enable you to type in commands.
A shell script will start its own bash session, for usually it does not know which shell you are using.
With Xwindows, you can have as many bash sessions working for you as you like, though you really do need just one.

3 Options and parameters

Actually, bash is used to start other processes and handling options and parameters to them.

A process is invoked by its name, followed by

This sounds thrilling and complicated, but it's not. I shall discuss this by the example
ls -l *
You know what this does: it gives a long list of the contents of the current directory.

Let's steep a little deeper:

It is a really easy syntax, istn't it?


4 Piping input and output

Let us pipe something, temporarily:
ls -l * > ~/myfiles.txt
The > sign takes the output not onto standard output, but into the file myfiles.txt. You should you less this file now to confirm yourself.

Linux processes tend to read from standard input (the keyboard) and to write processed data to standard output (the monitor).
So, of course, the input and output has to be redirected ("piped") by you, using ">" for output files and "<" for input files.
Most programs do without a "<". If you give them a file to process just by its name, most times they will do.

povray forms an exception. TeX also does:

tex thesis
will seek file thesis.tex.
If it finds it, it will automatically write to thesis.dvi.
If not found, TeX will process file thesis instead. Most likely, this is no TeX file, so TeX will complain.

Starting

tex
without a filename, it will read from standard input, that is the keyboard, and process and complain until you have this ended with \bye.

5 Foregrounding, Backgrounding and Killing of processes

yes
starts process yes, which throws and endless stream of y's to standard output, that is: the monitor.
C-z
[1] 456
stops process yes. yes was process no. 1 in this session of bash, and process no. 456 on the system.
fg %1
starts process no. %1 again, in the foreground.
C-z
[1] 456
stops process yes again. Numbers have not changed, this is the same process.
bg %1
starts yes in the background.
jobs
1 yes running
yes is still running, in the background.
kill 456
process 456 yes terminated
process yes is dead.
jobs
process 456 yes terminated
process yes is in fact dead.
yes &
starts another process yes in the background.
jobs
[2] 890 yes running
yes, it's running.
killall
[2] 890 yes terminated
another dead process.
killing by [session number], fg and bg are built-in bash commands, not available for other shells.

6 Writing shell scripts

As a very example, create file ll with vi:
#!/bin/bash                  # this script is for bash.
                             # a new bash session is started.

ls -l a* > ~/all.a.files     # create a list of all files starting with a,
                             # and store it in all.a.files
Now make ll executable, and run it.

There is syntax including if .. then, repeat .. until, while .. wend et cetera available.


This page hosted by Get your own Free Home Page