NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

simple calculator
echo "Enter Two numbers : "
read a
read b

# Input type of operation
echo "Enter Choice :"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
read ch

# Switch Case to perform
# calculator operations
case $ch in
1)res=`echo $a + $b | bc`
;;
2)res=`echo $a - $b | bc`
;;
3)res=`echo $a * $b | bc`
;;
4)res=`echo "scale=2; $a / $b" | bc`
;;
esac
echo "Result : $res"



Program in UNIX to convert Kilometers and print this distance in meters, feet, inches and centimeters.
echo -n "Enter distance in km : "
read km
m=`echo $km * 1000 |bc`
cm=`echo $m * 100 |bc`
ft=`echo $cm / 30 |bc`
in=`echo $cm / 2.5 |bc`
echo "Distance in meters : $m"
echo "Distance in feets : $ft"
echo "Distance in inches : $in"
echo "Distance in centimeters : $cm"


EVEN OR ODD IN SHELL SCRIPT:
HOW TO FIND A NUMBER IS EVEN OR ODD IN SHELL SCRIPT
# WRITTEN BY SURAJ MAITY
# TUTORIALSINHAND.COM
clear
echo "---- EVEN OR ODD IN SHELL SCRIPT -----"
echo -n "Enter a number:"
read n
echo -n "RESULT: "
if [ `expr $n % 2` == 0 ]
then
echo "$n is even"
else
echo "$n is Odd"
fi

Shell Script to Check if the Current Year is Leap Year or Not
leap=$(date +"%Y")
echo taking year as $leap
if [ `expr $leap % 400` -eq 0 ]
then
echo leap year
elif [ `expr $leap % 100` -eq 0 ]
then
echo not a leap year
elif [ `expr $leap % 4` -eq 0 ]
then
echo leap year
else
echo not a leap year
fi


Factorial of a number using while loop - Shell Script
echo "Enter a number"
read num

fact=1

while [ $num -gt 1 ]
do
fact=$((fact * num)) #fact = fact * num
num=$((num - 1)) #num = num - 1
done

echo $fact


How do I find prime number using Shell Script
#!/bin/bash
prime_1=0
echo "enter the range"
read n
echo " Primenumber between 1 to $n is:"
echo "1"
echo "2"
for((i=3;i<=n;))
do
for((j=i-1;j>=2;))
do
if [ `expr $i % $j` -ne 0 ] ; then
prime_1=1
else
prime_1=0
break
fi
j=`expr $j - 1`
done
if [ $prime_1 -eq 1 ] ; then
echo $i
fi
i=`expr $i + 1`
done


Fibonacci Series in Bash
# Program for Fibonacci
# Series

# Static input fo N
N=6

# First Number of the
# Fibonacci Series
a=0

# Second Number of the
# Fibonacci Series
b=1

echo "The Fibonacci series is : "

for (( i=0; i<N; i++ ))
do
echo -n "$a "
fn=$((a + b))
a=$b
b=$fn
done
# End of for loop


Shell Script to Sort Number in Descending Order
#!/bin/bash
echo "enter maximum number"
read n
# taking input from user
echo "enter Numbers in array:"
for (( i = 0; i < $n; i++ ))
do
read nos[$i]
done
#printing the number before sorting
echo " Numbers in an array are:"
for (( i = 0; i < $n; i++ ))
do
echo ${nos[$i]}
done
# Now do the Sorting of numbers
for (( i = 0; i < $n ; i++ ))
do
for (( j = $i; j < $n; j++ ))
do
if [ ${nos[$i]} -lt ${nos[$j]} ]; then
t=${nos[$i]}
nos[$i]=${nos[$j]}
nos[$j]=$t
fi
done
done
# Printing the sorted number in descending order
echo -e "nSorted Numbers "
for (( i=0; i < $n; i++ ))
do
echo ${nos[$i]}
done


#
#Write a script to display the name of all executable files in the given directory
#
clear
echo -n "Enter name of the directory :"
read directory

if [ ! -d $directory ]
then
echo "Directory not exist"
else
count=0
echo "Files with executable rights are"
#ONE SOLULTION IS
# for i in `ls $directory`
# do
# if [ -x $directory/$i ]
# then
# echo $i
# fi
# count=$(echo count + 1 | bc -l)
# done
for i in $(find $directory -type f -perm +111)
do
echo $i
count=$(echo count + 1 | bc -l)
done
if [ $count -eq 0 ]
then
echo "No files found with executable rights"
fi
fi


write a shell script to fetch the data from a file and display data into another file in reverse order.
if [ -f $fileName ]
then
str=`cat $fileName`

len=`echo $str|wc -c`

i=$len
while [ $i -ge 1 ]
do
temp=$temp`echo $str|cut -c $i`
i=`expr $i - 1`
done

echo $temp>Result_ex2f.txt
cat Result_ex2f.txt

else
echo "file [ $fileName ] not exist in c "
pwd
fi




     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.