How to Create Your First Bash Scrip
touch hello_world.sh
Find the path to your bash shell.
where bash is located
which bash
touch hello.sh
ls -al
Permission of file
#! bin bash
#! /bin/bash
echo "hello"
for execute
./hello.sh
Comment
# before line of comment
it give more information about script
++++++++++++++++++++++++++++++++++++++++++++++
when ever we define a
Variable it can store somedata string data any no or any other kind of data
1 System variable
2 Userdefine variable
System variable
echo $BASH
echo $BASH_VERSION
echo $HOME
echo $HASH_VERSION
echo $PWD
2. USERDEFINE VARIABLE
name = Mark
echo $name
echo "this is my $name
+++++++++++++++++++++++++
#To take the input from user
echo "enter name: "
read name
echo "entered name $name"
++++++++++++++++++
for multiple name
echo "enter name: "
read name1 name2
echo "Names: entered $name, $name1, $name2"
+++++++++++
to print on same line
read -p 'usename: 'user_var
echo "username : $user_var"
to take the input silent without displaying what you typing on the screen
read -sp 'password' : 'pass_var'
echo "password : $pass_var"
++++++++++++++++++++++++++++++++++++++++++++++
How to pass argument at the time of execution
echo $1 $2 $3 ' > echo $1 $2 $3 '
./hello.sh Mark Pranav John
It store in $1 Mark ....and all
+++++++++++
2nd method pass with array
array start from 0 th index
args=("$@")
echo ${args[0]} ${args[1]} ${args[2]}
++++++++++++++++++++++++++++
4) Condn Statement
synt:-
if [codn]
then
statement
fi
Ex:-
count = 10
if [$count -eq 9] / #[$count -gt 9]
then
echo "condn is true"
fi
++++++++
Integer compa oper
-eq - is equal to
-ne - nt equal to
-ge - gret equ to
-lt - less than
-le - less than equal to
< - is less than
> - is greater than
>= - gre eql to
!= - not equl to
++++++++++++++++++++++++++
Comp
word=abc
if [$word == "abccc"]
then
echo "codn is true"
fi
Comments
Post a Comment