How to create a word replacing Bash script on Ubuntu 21.04
To Create a word replacing Bash script on Ubuntu 21.04
Introduction:
The bash shell program was written by Brian Fox as an upgraded version of Bourne Shell's sh program. Bash provides the ability to view or modify the readline key bindings with the bind built-in command.
Installation Procedure:
Step 1: Check the OS version by using the below command
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute
Step 2: Creating a sample content file by using the below command
root@linuxhelp:~# vim test
Unix was Powerfull
Unix was close source
Unix trademarked as Unix was a family of multitasking,
multiuser computer
operating systems that derive from the original AT&T Unix,
whose development started in 1969
Step 3: Create the word replacing Bash Script by using the below command
root@linuxhelp:~# vim sample.sh
#!/bin/bash
while true; do
echo "Enter the File Name"
read var1
echo "Select the Pattern"
read var2
echo "Select the Replacing Pattern"
read var3
echo "Working Please Wait"
sed -i s/$var2/$var3/g $var1
cat $var1
echo
read -p "Do you wish to run this program again?, Press y for yes and n for NO " y
case $y in
[Yy]* ) sh sample.sh ;;
[Nn]* )
echo
echo "Process Completed"
echo "Bye"
exit ;;
esac
done
Step 4: Give Execute Permission to the Script file by using the below command
root@linuxhelp:~# chmod +x sample.sh
Step 5: View the Permissions by using the below command
root@linuxhelp:~# ls -la sample.sh
-rwxr-xr-x 1 root root 451 Jan 21 06:33 sample.sh
Step 6: Execute the Script file by using the below command
root@linuxhelp:~# sh sample.sh
Enter the File Name
test
Select the Pattern
Unix
Select the Replacing Pattern
Linux
Working Please Wait
Linux was Powerfull
Linux was close source
Linux trademarked as Linux was a family of multitasking,
multiuser computer
operating systems that derive from the original AT&T Linux,
whose development started in 1969
Do you wish to run this program again?, Press y for yes and n for NO y
Enter the File Name
test
Select the Pattern
Linux
Select the Replacing Pattern
Unix
Working Please Wait
Unix was Powerfull
Unix was close source
Unix trademarked as Unix was a family of multitasking,
multiuser computer
operating systems that derive from the original AT&T Unix,
whose development started in 1969
Do you wish to run this program again?, Press y for yes and n for NO n
Process Completed
Bye
With this the process of creating a word replacing Bash script on Ubuntu 21.04 has come to an end.
Comments ( 0 )
No comments available