[home] [<-back] [index] [next->]




 ____________________________________________________________________
 
[ 5:. - [ Introduction to the BASH Shell ]                [fluid] :. ]
                                    [markus@fluidenterprises.net] :. ]
 ____________________________________________________________________


Intro

The bourne-again shell, or bash for short, is quickly becoming a very popular
shell. The bash shell has many great features, including many advantages the
the C and Korn shell have. Bash has command-line features which usually get
lots of notice. Another major feature is its job controls. Bash has become so
popular that it is usually used as the default shell for linux operating
systems.

Basics

To execute a command in bash, you have to supply the directory and executable
name. If I wanted to execute party in my /root/personal folder, I'd do
/root/personal/party. People quickly found this inconvenient so the programmers
developed a thing call working directory. You can navigate directories using
the 'cd'(change directory) command. If you are lost, typing 'pwd' will show you
your current working directory. In order to know where your going, your going
to have to see what's in the directory. That can be accomplished by using the
'ls' command. There are special characters in bash as showed in the table below

character | function
========================
.      | means the current directory
..      | means the parent directory
?      | represents 1 character of anything
*      | represents infinite characters of anything

These 4 will now be explained with examples. If you were in /root/personal and
you wanted to execute party which was in the directory you were in, you
couldn't just type party. If you just type party, it'd search in your PATH
locations, which are defaultly set to /bin, /usr/bin, /usr/local/bin,
/usr/sbin and /sbin. Instead you'd have to do './party' meaning in the current
directory, run party. If you were in /root/personal/mail and wanted to run
party, you could do '../party', which would mean in the parent directory(the
one right before it) run party. If you were in /root/personal and type 'cd ..'
it would take you to /root. Now for the ? and * examples. If you had the
following files in a directory:

baaaaaabby beebby bibby bobby and bubby

If you typed 'ls b?bby' you'd be saying list all the files which start with a
b, then have any character, then ends with bby.

ls b?bby
will list:
bibby bobby bubby

If you did 'ls b*bby' you'd be saying list all the files which start with a b,
then have any amount of any characters, then ends with a bby.

ls b*bby
will list:
baaaaaabby beebby bibby bobby bubby

The * character is useful for when you want to see all the files starting with
a certain letter, or to see all of a certain of file. Examples:

ls h*
ls *.c

If you ever want to goto your home directory or use it, you can use ~. If your
username is joesmith and you type 'cd ~' it would take you to
/home/joesmith(or where-ever your home is)

Bash Input/Output
By default, executables take their input from the keyboard, and print there
output to the screen, but this can be changed. If I wanted to redirect the
output from the command 'ls' to a file, I'd do 'ls ] file'. That would direct
all the information the ls would print to the screen into the file "file". If
you wanted to input all the contents of a file into a command, you can use the
[ command. Such as "more [ file" that would take everything from file and put
it into the more command. If you wanted to see all the info from ls in the
more format, you could do it in two commands like this 'ls ] file' and 'more [
file'. Or you could use a | and do it in one command 'ls | more'. That takes
the output from ls and puts it as input for more. Another example of using the
| is 'cut =d: -f5 [ /etc/passwd | sort' That would grab all the names from the
passwd file and sort them out.

Background/Foreground

Normally when you run a program it has full control over the terminal until
the program is done running. Then it throws you back into the shell. Well,
this OS isn't called multi-tasking for nothing. If you want to run a program
in the background so you never have to deal with it, put an & at the end of
the command.

Example:
bash# tar xvf big_file.tar &
[1] 2486
bash#

The [1] means it's job number 1 and the second number is the process. I'll go
into details with processes later.

What we just did is move the program into the background. But what if we want
to see what it's doing, well, we can use the foreground command('fg').

bash# fg 1

Now the program is running in the foreground at the terminal.

If you wanted to stop the program from running, you could do.

bash# kill %1

The process is now killed. Instead of using %1, you could have used 2486 (the
process ID).

If a program was running in the terminal, and you wanted to kill it or put it
in the background, you could use CTRL+Z. If we did CTRL+Z while tar was
un-taring it's file, we'd see

[1]+ Suspended        tar xvf big_file &

Right now the program is paused. If we wanted it to goto the back ground we'd
us bg 1, foreground, fg 1, kill it, kill %1.


Processes

To get a list of all the processes currently running, use ps (or ps -aux for
more info).Remember, if the list flies by too quick, you can use ps | more.

If you see a process there you'd like to kill, you can use the kill [process]
command. If that doesn't work, they you can use kill -9 [process]

BASH Environment Varibles

In this part of the BASH Shell tutorials we'll look at BASH Environment
Varibles, how-to edit ~/.profile and ~/.bash_profile and how to set and
use some common varibles.

Sample .bash_profile

To understand how the .bash_profile works, lets first take a look a mine:

fluid@fluidenterprises:~/$ more .bash_profile

# Set environmental variables
SHELL=/bin/bash
EDITOR=/usr/bin/vi
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin
MANPATH=/usr/man:/usr/X11/man
PS1='u@h:w$ '
PS2='] '

# Run any commands
mesg y

fluid@fluidenterprises:~/$

Let me go through this file line by line.

The first line "# Set environmental variables" is a comment, all comments
in bash, sh and makefile scripts start with a #.

The second line "SHELL=/bin/bash" is your default SHELL. Set it to your
favorite shell.

The third line "EDITOR=/usr/bin/vi" is your default EDITOR. Programs will
run EDITOR when they need you to edit a file, therefore set EDITOR to your
favorite text editor.

The fourth line "PATH=/directory:/directorytwo" is the PATH's your shell
will use when searching for a command. If you ran the command "vi" the
shell would search through each of those directories, in order. If it
found a program called vi in one of those directories, it'd run it, if it
didn't find any program called vi, it would reply command not found.

The fifth line "MANPATH=/directory:/directorytwo" is the path's your shell
will use when searching for a manpage. It'll search each of those
directories in order until it finds or not finds the man page.

The sixth line "PS1='u@h:w$ '" is what your prompt will be, if you
notice in the above example my prompt is fluid@fluidenterprises:~/$
d = date
h = host name
s = shell name
	 = time
u = user name
w = working directory

The seventh line "PS2='] '" is what your prompt will be when your using
more then one line as the prompt. The same commands as above work for it.

The tenth line "mesg y" just runs the command mesg with the y argument,
which means people are allowed to request talk sessions with you and they
can write to you.

All of the command the above .bash_profile could be typed in manually
everytime you logged in. Using .bash_profile makes that a lot more
conveniant.

Markus "Fluid" Delves
markus@fluidenterprises.net
http://www.fluidenterprises.net










b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!
b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!

From: playaray@excite.com
To: k-rad-bob@b0g.org

can u tell me 1.how to install text messagibg onto my nokia
5160 so i can recieve them and write back.

can u tell me how 2 phreak a gte qualcomm

b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!
b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!b0g!#@!








[^-top] [next->]