MagLite Solitaire Single AAA Cell Flashlight

The perfect technician's flashlight
Click Here!
: : : : : : : :    h o m e   :|:   A l l   i n   G e n e r a l   O u t d o o r s   :|:   M a g l i t e   S a l e s   :|:   m y   r e s u m e   
 L i n u x H e l p  : : : : : : : :

Shell scripting quick start


There are a few basic things that one must understand about how a shell works in order to understand how to write scripts. I will try to be as brief and to-the-point as I can possibly be throughout this tutorial.

Shell redirection
There are three fundamental ways to redirect input and output in your shell.

A "pipe" |
Overwrite > or <
Append >> or <<


Starting to write the script:

She-Bang (Hash (#) Bang (!))

The She-Bang is the first line in any shell script and is the actual execute line for the script. In other words, the script executes using the program pointed to by the she-bang. Normally, any line in a shell script that begins with a "#" is a comment. The she-bang is an exception.
#!/bin/bash

Variables

Run the command 'env' on your shell and you will see all of the variables that your shell currently has set. You can set variables like these for use in your shell scripts. *NOTE* From this point on in this tutorial, each of the scriptlets can be copied to your favorite editor and will run as displayed here. Copy one and play around with it to see how it ticks.
#!/bin/bash
VAR="0"      # Set the variable
echo $VAR    # echo it to the shell

if-then construct

Now that you know how to assign a variable, we're going to learn how to test for that variable and execute differently based on the variable's value.
#!/bin/bash
VAR="0"

if [ $VAR -eq "0" ]; then    # if $VAR is equal to 0
    echo "The variable \$VAR is set to 0"
else
    echo "The variable \$VAR is not set to 0"
fi

for loop

#!/bin/bash
VAR="foo bar baz"

for member in $VAR    # for each member of $VAR
do
    echo $member      # echo $member to the shell
done 

while loop

#!/bin/bash
i="0";

while [ $i -le 10 ];  # while $i is less than or equal to 10
do
    echo $i;          # echo $i to the shell
    let i=$i+1;       # increment $i by 1
done 

Reading input from the shell

#!/bin/bash

echo "Is this fun, or WHAT?!?  [y/n]"
read ANSWER

if [ $ANSWER == "n" -o $ANSWER == "N" ]; then
    echo "Oh, you're not having fun?  Well, I am!"
elif [ $ANSWER == "y" -o $ANSWER == "Y" ]; then
    echo "I'm glad you're enjoying yourself ;-)"
else
    echo "You must answer the question with \"y\" or \"n\""
    echo
    $0
fi
 L i n u x   W o r l d   N e w s   : : : : : : : :


What in the hell is a KrnlPanic? Well, a KrnlPanic is me! Actually, let's start with "What is a kernel?". The kernel is the core of your operating system (OS), whether your OS is Linux, Unix or windows. The kernel takes care of all process management (what program runs and when), memory management (which parts of memory get used for what) and also, the kernel takes care of interfacing the OS with your computer's hardware (disk drives, sound card, modem, network card, etc).

Now...since the kernel is doing all of these extremely important jobs, it stands to reason that if it has an error, it will be a Bad Thing(tm). If you use windows, you know a kernel panic as a "BSOD" or Blue Screen of Death. Or how about "Invalid Page Fault in KERNEL32.DLL". I'm sure you've probably seen both of those. In Linux, a Kernel Panic is normally plainly stated so. At boot time is when you will see most linux panics. I have yet to see a linux kernel panic while the system is running. You may have seen "Kernel Panic: init not found" or "Kernel Panic: VFS unable to mount root fs on 2:00". All of these previously listed errors are because of something that happened to the kernel that it couldn't handle, whether it was an access to an invalid memory location or the inability to find the initialization files it requires.

I hope that sufficiently explains things. Oh yeah...KrnlPanic is also my name ;-)

- Rick

 S l a s h d o t / F r e s h m e a t   : : : : : : : :
Slashdot and Freshmeat Headlines at 1328383374 (Unixtime)

Slashdot.org Home

o Milky Way Magnetic Fields Charted
o New Book Helps You Start Contributing To Open Source
o $100,000 Prize: Prove Quantum Computers Impossible
o President By Day, High-Tech Headhunter By Night
o You Will Never Kill Piracy
o New Mobile Plan Pools Data On Unlimited Devices
o The Destruction of Iraq's Once-Great Universities
o World's Largest Virtual Optical Telescope Created
o Facebook On Collision Course With New EU Privacy Laws
o Researchers Feel Pressure To Cite Superfluous Papers
Freshmeat.net Home

Freshmeat headlines seem to be having problems. Will get this working again soon.
 
Search Slashdot:
Search Freshmeat:
Search for linux books or other merchandise @ Amazon.com

Search:
Keywords:
In Association with Amazon.com

Google
: : : : : : : :  K r n l P a n i c   : : : : : : : :
Disclaimer: The documents on this site are to be taken as-is, and I accept no responsibility for damages that may occur from errors or omissions in any of the documents on this site or referred to by this site. By using any of these help documents, you agree to this disclaimer.          ***This site best viewed at 1024x768 or better screen resolution.***