diff --git a/OS/bash/Week3/addq1.sh b/OS/bash/Week3/addq1.sh new file mode 100644 index 0000000..f15a41f --- /dev/null +++ b/OS/bash/Week3/addq1.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "Enter a number" +read no + +is_prime=true + +if [ "$no" -lt 2 ]; then +is_prime=false +else +for((i=2; i <=$((no/2)); i++));do +if [ $((no % i)) -eq 0 ];then +is_prime=false +break +fi +done +fi + +if [ "$is_prime" = true ];then +echo "$no is prime" +else +echo "$no is not prime" +fi diff --git a/OS/bash/Week3/addq2.sh b/OS/bash/Week3/addq2.sh new file mode 100644 index 0000000..6115a94 --- /dev/null +++ b/OS/bash/Week3/addq2.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +echo "Enter a number" +read no + +fact=1 + +for((i=1;i <= no; i++));do +fact=$((fact*i)) +done + +echo "The factorial is $fact" diff --git a/OS/bash/Week3/addq3.sh b/OS/bash/Week3/addq3.sh new file mode 100644 index 0000000..47f6103 --- /dev/null +++ b/OS/bash/Week3/addq3.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +echo "Enter the text file" +read file + +even_file="evenfile" +odd_file="oddfile" + +line_no=1 +while IFS= read -r line;do +if [ "$((line_no%2))" -eq 0 ]; then +echo "$line" >> "$even_file" +else +echo "$line" >> "$odd_file" +fi +((line_no++)) +done<"$file" + +echo "Even and odd numbered lines transferres" + diff --git a/OS/bash/Week3/q1.sh b/OS/bash/Week3/q1.sh new file mode 100644 index 0000000..e9c36c0 --- /dev/null +++ b/OS/bash/Week3/q1.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Enter the name of item to be checked" +read name +if [ -f $name ]; then +echo "File $name exists" +elif [ -d $name ]; then +echo "Directory $name exists" +else +echo "Neither file or directory" +fi diff --git a/OS/bash/Week3/q2.sh b/OS/bash/Week3/q2.sh new file mode 100644 index 0000000..a2c73c1 --- /dev/null +++ b/OS/bash/Week3/q2.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +echo "Which folder would you like to check?" +read folder +echo "Enter pattern/filename string to match" +read string +x=`find $folder -type f -iname "*$string*"` +for i in $x;do +echo "$i" +done