Upload files to "OS/bash/Week3"
This commit is contained in:
parent
49b7d5d30c
commit
e27e2c7837
23
OS/bash/Week3/addq1.sh
Normal file
23
OS/bash/Week3/addq1.sh
Normal file
@ -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
|
12
OS/bash/Week3/addq2.sh
Normal file
12
OS/bash/Week3/addq2.sh
Normal file
@ -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"
|
20
OS/bash/Week3/addq3.sh
Normal file
20
OS/bash/Week3/addq3.sh
Normal file
@ -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"
|
||||
|
11
OS/bash/Week3/q1.sh
Normal file
11
OS/bash/Week3/q1.sh
Normal file
@ -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
|
10
OS/bash/Week3/q2.sh
Normal file
10
OS/bash/Week3/q2.sh
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user