Skip to content

Commit baeae02

Browse files
authored
Merge pull request #726 from rishabh-malik/master
added shell scripting
2 parents 48ff213 + 564295d commit baeae02

16 files changed

+151
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#arithmetic operations on float and real nos
2+
a=10.5 b=3.5
3+
# using | for feeding arithmetic operations to bc
4+
c=`echo $a + $b | bc`
5+
d=`echo $a - $b | bc`
6+
e=`echo $a \* $b | bc`
7+
f=`echo $a / $b | bc`
8+
echo $c $d $e $f
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#arithmetic operations using expr
2+
a=30 b=15
3+
echo `expr $a + $b`
4+
echo `expr $a - $b`
5+
echo `expr $a \* $b`
6+
echo `expr $a / $b`
7+
echo `expr $a % $b`

shell_scripting/break-statement.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#while loop in action
2+
count=1
3+
while [ $count -le 10 ]
4+
do
5+
if [ $count -eq 4 ]
6+
then
7+
break
8+
fi
9+
echo $count
10+
count=`expr $count +1`
11+
done
12+
13+

shell_scripting/case-statement.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
echo "Enter a character:\c"
2+
read var
3+
case $var in
4+
#matching var to from a to z
5+
[a-z])
6+
echo "You entered a lowercase alphabet"
7+
;;
8+
#for ending case ;;
9+
[A-Z])
10+
echo "You entered a uppercase alphabet"
11+
;;
12+
[0-9])
13+
echo "You entered a digit"
14+
;;
15+
?)
16+
echo "You entered a special character"
17+
;;
18+
*)
19+
echo "You entered multiple characters"
20+
;;
21+
esac
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#to change the permission of file from script
2+
chmod 744 $1
3+
ls -l $1

shell_scripting/continue.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#while loop in action
2+
count=1
3+
while [ $count -le 10 ]
4+
do
5+
if [ $count -eq 4 ]
6+
then
7+
continue
8+
fi
9+
echo $count
10+
count=`expr $count +1`
11+
done
12+
13+

shell_scripting/counting.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#count the no of positional parameters
2+
#count no of items
3+
echo "total no of items in current dir is: $#"

shell_scripting/elif.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
echo "Enter a no between 10 and 20:\c"
2+
read num
3+
#lt=less than
4+
if [ $num -lt 10 ]
5+
then
6+
echo "Under 10"
7+
#greater than
8+
elif [ $num -gt 20 ]
9+
then
10+
echo
11+
echo "More than 20"
12+
else
13+
echo "thats right"
14+
fi

shell_scripting/escape-sequence.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#escape sequences in echo
2+
echo "hello world"
3+
#new line
4+
echo "hello \nworld"
5+
#carriage return
6+
echo "hello \rworld"
7+
#tab
8+
echo "hello \tworld"
9+
#backspace
10+
echo "hello world \b\b\b"
11+
#bold
12+
echo "\033[1mHello world\033[0m"
13+
#reverse video format
14+
echo "\033[7mHello world\033[7m"

shell_scripting/file-test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#check if the given file exist in following dir or not
2+
echo "Enter a name:\c"
3+
read fname
4+
#-f for file -d for dir
5+
#-s for size
6+
if [ -f $fname ]
7+
then
8+
echo "Yes its a file"
9+
else
10+
echo "No its not a file"
11+
fi

0 commit comments

Comments
 (0)