-->

How to Executing commands in a shell script


Hello guys in this tutorial we are going to discuss about executing shell scripting.so far we have learned basic concepts including syntax.now let's do some tasks in pro way.





By using this method you can executive multiple commands at time.
Ex: Kumar is watching Tv and drinking coffee. 
let's go in code way.
Just place commands in bash script
This code is quite easy to memorize.Have a try on it.You need to write commands in a specific order to run and execute.
#!/bin/bash

ls-l

mkdir

linux java

free -m

who

where in 1st line indicates shebang also called bash interpreter

in second line ls is a commandto list content in current directory.

in third line mkdir will create two directories named java and Linux.

in Fourth line free-m shows freespace in Ram,Rom,Hard disk.

However you write code then the terminal execute that commands in that pattern.write code in pro way with your creativity.

Upgrade Linux using bashscript to new version.

By using this command it deletes the old Linux package and updates to new version.The code is quite lengthy.Just paste below code in terminal and hit enter

apt-get clean && apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y


Lets Copy  files with  shell  scripting





#!/bin/bash
echo "Enter file to be copied"
read old
echo "Enter new file name "
read new
if cp $old $new
then
echo "file successfully copied"
else
echo "file does not exits"
fi

Where first line ask user to enter the name to copy but it must be in present working directory.
Where Second line stores back up file name .
if statement can be used to check whether if operation has successfully been performed or not, if operation is not successfully performed then it shows error result on output screen.
you can use mv command for renaming and -r for copying and renaming current directories.

conclusion


I hope you may loved this cool post.If you have any doubts post in comment section.
Please check out advertisements on our website which helps us to post more content for you .
 Don't forget to share this cool post with all your friends and groupspread. HAVE  A  GREAT  DAY. 

Also Read

Post a Comment