Skip to content

Commit 9319567

Browse files
committed
Adding Files
0 parents  commit 9319567

File tree

7 files changed

+160
-0
lines changed

7 files changed

+160
-0
lines changed

1.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# creating a menu with the following options
4+
echo "1. Find Odd or even number"
5+
echo "2. Find smallest among three numbers"
6+
echo -n "Enter your menu choice [1-4]: "
7+
8+
# Running a forever loop using while statement
9+
# This loop will run untill select the exit option.
10+
# User will be asked to select option again and again
11+
while :
12+
do
13+
14+
# reading choice
15+
read choice
16+
17+
# case statement is used to compare one value with the multiple cases.
18+
case $choice in
19+
# Pattern 1
20+
1)echo -n "Enter a number:"
21+
read n
22+
if [ `expr $n % 2` == 0 ]
23+
then
24+
echo "$n is even"
25+
else
26+
echo "$n is Odd"
27+
fi;;
28+
29+
# Pattern 2
30+
2)echo "enter num_1: "
31+
read num1
32+
echo "enter num_2: "
33+
read num2
34+
echo "enter num_3 : "
35+
read num3
36+
s=$num1
37+
if [ $num2 -lt $s ]
38+
then
39+
s=$num2
40+
fi
41+
if [ $num3 -lt $s ]
42+
then
43+
s=$num3
44+
fi
45+
echo Smallest of $num1 $num2 $num3 is $s;;
46+
47+
# Default Pattern
48+
*) echo "invalid option";;
49+
50+
esac
51+
echo -n "Enter your menu choice [1 or 2]: "
52+
done

2.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Taking two numbers from command line argument and finding grater among them .
2+
3+
echo "num1: $1"
4+
echo "num2: $2"
5+
6+
#Condition for greater number
7+
if [ $1 -gt $2 ]
8+
then
9+
echo "$1 is greater than $2"
10+
else
11+
echo "$2 is greater than $1"
12+
fi

3.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
file="$1"
3+
4+
#Checking file is writable or not
5+
if [ -w "$file" ]
6+
then
7+
echo "TRUE.....Write permission is granted on $file"
8+
else
9+
echo "False....Write permission is NOT granted on $file"
10+
fi
11+
12+
#Checking file is executable or not
13+
if [[ -x "$file" ]]
14+
then
15+
echo "File '$file' is executable"
16+
else
17+
echo "File '$file' is not executable or found"
18+
fi
19+
20+

4.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash/
2+
3+
DAY=$(date +"%A")
4+
5+
case $DAY in
6+
7+
Monday)
8+
echo -n "Monday is new start in life!!"
9+
;;
10+
11+
Tuesday)
12+
echo -n "Lets do things with same energy!!"
13+
;;
14+
15+
Wednesday)
16+
echo -n "Happy hump day!!"
17+
;;
18+
19+
Thursday)
20+
echo -n "Thursday brings full energy!!"
21+
;;
22+
23+
Friday)
24+
echo -n "TGIF!!"
25+
;;
26+
27+
Saturday)
28+
echo -n "Have a Saturday full of happiness and joy!!"
29+
;;
30+
31+
Sunday)
32+
echo -n "Have a wonderful weekend!!"
33+
;;
34+
35+
*)
36+
echo -n "Have a nice day!!"
37+
;;
38+
esac

5_onecommand.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
ls

5_separate.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# To display Files and Folders in current directory
2+
3+
echo "Directories : "
4+
for dir in *
5+
do
6+
if [ -d $dir ]
7+
then
8+
echo $dir
9+
fi
10+
11+
done
12+
13+
echo "Files : "
14+
for dir in *
15+
do
16+
if [ -f $dir ]
17+
then
18+
echo $dir
19+
fi
20+
21+
done

README.MD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Shell Script Assignment
2+
3+
1. Write a menu driven program for 1. Odd or Even Number 2. Find smallest number amongst three numbers
4+
5+
6+
2. Create a Bash script which will take two numbers as command line arguments. It will print to the screen the larger of the two numbers.
7+
8+
9+
3. Create a Bash script which will accept a file as a command line argument and analyse it in certain ways. eg. you could check if the file is executable or writable. You should print a certain message if true and another if false.
10+
11+
12+
4. Create a Bash script which will print a message based upon which day of the week it is (eg. 'Happy hump day' for Wednesday, 'TGIF' for Friday etc).
13+
14+
15+
5. Write a shell script to display files and folders from current directory

0 commit comments

Comments
 (0)