Bash Scripting

In this post we will look at basic bash scripting.


Bash scripting
[pre class="brush:bash"]
vim temp.sh

#!/bin/bash
echo “Hello world…”
Sleep 1
echo “How are you?”
read ans
echo “you typed $ans”

chmod +x temp.sh

./temp.sh[/pre]

How to run a bash script from anywhere
[pre class="brush:bash"]
# create a directory say "bin" under your home directory.
# update your path variable to include this bin directory.
#Put this in .profile or .bash_profle file to make it permanent.
export PATH=$PATH":$HOME/bin"
#or use the following, if you want the directory to precedent system directories
PATH=$HOME/bin:$PATH;
# create a script say, "hello" and keep it in your bin directory.
#Give execute permission to the hello script.

#!/bin/bash
echo My first program

# from any directory, you simply type:
$ hello
My first program[/pre]

You may also interested in reading:

No comments:

Post a Comment