LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-30-2013, 07:13 AM   #1
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 47

Rep: Reputation: 0
Editing a file within a script and then continueing


Hi there,
Can someone please help out with this.

I am running a script and want to add the option of viewing and amending a file, then continue to the script.

If the user enters y, the file will be opened for editing. When editing is done, I want to continue the script.
Pressing n will continue the script,

I have ..

read -p "****** To change the file press y or n to continue" choice
echo ""
case "$choice" in
y|Y )
vi $statfile
;;
n|N ) echo "no";;
* ) ;;
esac

echo "contine script"

Many thanks
 
Old 05-30-2013, 07:29 AM   #2
kaushalpatel1982
Member
 
Registered: Aug 2007
Location: INDIA
Distribution: CentOS, RHEL, Fedora, Debian, Ubuntu, LinuxMint, PCLinuxOS
Posts: 153

Rep: Reputation: 9
Find the bash file as below:
===============================
#!/bin/bash
trap "" 2 20
while :
do
clear
echo 1. open file
echo 2. exit
read option;

case $option in
1)
vi test.txt
;;
2)
exit
;;
esac
done
==================================
I hope this will help you.
 
Old 05-30-2013, 08:09 AM   #3
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 47

Original Poster
Rep: Reputation: 0
Thanks for that.

After the filehas been opened for editing, I need to continue with the rest of the script.

How do I do that ?

Thanks
 
Old 05-30-2013, 08:20 AM   #4
kaushalpatel1982
Member
 
Registered: Aug 2007
Location: INDIA
Distribution: CentOS, RHEL, Fedora, Debian, Ubuntu, LinuxMint, PCLinuxOS
Posts: 153

Rep: Reputation: 9
SmurfGGM,

I didnt get you. are you calling this script from other script?

What I was understand, When you complete with editing file, you should be back to menu.
 
Old 05-30-2013, 08:45 AM   #5
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 47

Original Poster
Rep: Reputation: 0
When I finish editing the file that is called by the script, I want the script to continue running.

Thanks
 
Old 05-30-2013, 08:50 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
So where are you stuck? All seems ok.

Just try it, and let's know if you have any issue:
Code:
#!/bin/bash
read -p "Enter the filename to be edited: " file
read -p "To change the file press y or n to continue: " choice
case $choice in
y|Y)
vi $file
echo "File editing done" ;;
n|N) echo "File was not edited.";;
*) ;;
esac
echo "Continue script..."
 
Old 05-30-2013, 09:09 AM   #7
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 47

Original Poster
Rep: Reputation: 0
Thanks

I get

read: -p: no coprocess
Continue script...
 
Old 05-30-2013, 09:27 AM   #8
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 47

Original Poster
Rep: Reputation: 0
ah i got it working with ..


read resp1?"To change the file press y or n to continue: "
case $resp1 in
y|Y)
vi $statfile
echo "File editing done" ;;
n|N) echo "File was not edited.";;
*) ;;
esac
echo "Continue script..."

Thanks for your time
 
Old 05-30-2013, 09:30 AM   #9
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Script is running fine on my system, so I guess you made some mistake. Once invoke the script with -xv option to see that where it goes wrong, as:
Code:
~$ bash -xv scriptname.sh
EDIT: You can even make it little simple, as:
Code:
#!/bin/bash
echo -n "Enter the filename to be edited: "; read file
echo -n "To change the file press y or n to continue: "; read choice
case $choice in
y|Y)
vi $file
echo "File editing done" ;;
n|N) echo "File was not edited.";;
*) ;;
esac
echo "Continue script..."

Last edited by shivaa; 05-30-2013 at 09:33 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Editing a file using sed within a script t_tunewiki Linux - Newbie 3 02-28-2012 01:28 PM
Conditional editing of a file through Shell script Linuxahoy Linux - General 2 01-23-2012 05:45 AM
editing file with script B-Boy Programming 4 09-02-2009 09:23 AM
Need help no editing a file through a script procfs Programming 7 07-19-2006 06:59 AM
file editing in a bash script Harpune Programming 4 11-23-2002 12:35 AM


All times are GMT -5. The time now is 06:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration