Sailing Through The World of Linux BASH Scripting – Part III - Cloud Network

Networking | Support | Tricks | Troubleshoot | Tips

Buymecoffe

Buy Me A Coffee

Thursday, March 5, 2015

Sailing Through The World of Linux BASH Scripting – Part III





Hello Everyone,

In this tutorial,

Let Us Create a Sailing Through The World of Linux BASH Scripting – Part III

You Can also Configure in Redhat Linux, Ubuntu, Fedora, CentOS, LinuxMint, Oracle Linux, Cloud Linux.

Move Current Working Directory
Create a Random File or Folder
Script to Converts UPPERCASE to lowercase
Simple Calculator Program

 Move Current Working Directory

#! /bin/bash

LEVEL=$1

for ((i = 1; i <= LEVEL; i++))

do

CDIR=../$CDIR done cd $CDIR

echo "You are in: "$PWD

exec /bin/bash

Create a Random File or Folder

#! /bin/bash

echo "Hello $USER";

echo "$(uptime)" >> "$(date)".txt

echo "Your File is being saved to $(pwd)“

echo‘ : Prints everything written within the quotes.

‘$‘ : Is a shell variable.

‘>>‘ : The output is redirected to the output of date command followed by txt extension

 Script to Converts UPPERCASE to lowercase

touch small.txt

#!/bin/bash

echo -n "Enter File Name : "

read fileName

if [ ! -f $fileName ]; then

echo "Filename $fileName does not exists"

exit 1

 fi

tr '[A-Z]' '[a-z]' < $fileName >> small.txt

Simple Calculator Program



#! /bin/bash

clear

sum=0

i="y"

echo " Enter one no."

read n1

echo "Enter second no."

read n2

while [ $i = "y" ]

do

echo "1.Addition"

echo "2.Subtraction"

echo "3.Multiplication"

echo "4.Division"

echo "Enter your choice"

read ch

case $ch in



1)sum=`expr $n1 + $n2`

     echo "Sum ="$sum;;

        2)sum=`expr $n1 - $n2`

     echo "Sub = "$sum;;

    3)sum=`expr $n1 \* $n2`

     echo "Mul = "$sum;;

    4)sum=`expr $n1 / $n2`

     echo "Div = "$sum;;

    *)echo "Invalid choice";;

esac

echo "Do u want to continue (y/n)) ?"

read i

if [ $i != "y" ]

then

    exit

fi

done


NOTE :- For Any Clarification Please Below
 
Comment,
Like and
Share  us  and  help us to spread.

####--------------------------------------------------------------------------------------####
Website    :-   http://www.cloudnetwork.in
Twitter     :-   http://twitter.com/itcloudnet
Skype Id  :-   cloud.network1
E-Mail Id :-   itcloudnet@gmail.com
####----------------------------------------------------------------------------------------####                         
Thanking You
Hope U Like it........
 
Comment Policy We’re eager to see your comment. However, Please Keep in mind that all comments are moderated manually by our human reviewers according to our comment policy, and all the links are nofollow. Using Keywords in the name field area is forbidden. Let’s enjoy a personal and evocative conversation.