4/13/2011

Bash scripting- The Basics

What is bash scripting?
Bash scripting is a type of shell scripting in Linux. Other types of shell scripts include csh, tcsh, ksh, zsh etc.



echo "something" - something will be displayed
sleep 5                - waits for 5 secs. You can also give 3m, m for minutes or 8h, h for hours

echo "print this to a file" > file.txt          -prints the stuff inside "  " to the file after the >
Next time you enter something into this file this way, the data entered earlier will be lost. In order to prevent this,
use,
echo "print this "  >> file.txt (notice the double >>)

The first line in a bash script should be #!/bin/bash
Give .sh extension to the file.
Make it an exe file using the command chmod +x file.sh  (change mode)

Now you can run it using ./file.sh
clear for clearing the screen
read asf for inputing data(asf is just an example,you can use anything)
$asf for outputing the value stored inside the variable

A sample bash script
Next, I make the file an executable using chmod +x file.sh. Then I run it using ./file.sh
This will give an output like this   
                                                                                 
It prompted me for an input and I typed backtrack rockss. When I push enter, I got

No comments:

Post a Comment