Accepting user input in Bourne shell and using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accepting user input in Bourne shell and using sed
# 1  
Old 09-09-2007
Accepting user input in Bourne shell and using sed

He guys.

Basically I want to make a script that can add, delete and view stuff in a external file called config.txt. I can open it up in Joe but im not sure how to read in the user input or using commands automatically in joe to edit, save then quit.

Problem area below:

Code:
 1) echo "Add option selected, ctrl k then s to save, ctrl k q to quit"
    sleep 2
    echo "Enter setting (format: ABCD=abcd): EDITOR=joe"
    read $add
   # case $add in  
    joe config.txt                                  
    echo "File changed"                 
    echo "Press any key to continue" ; read ;;

As you can see the case statement is making issues with it, if commented out, if lets the script run and enter joe and stays there wanting the user to use it properly. What is the best way?

Rest of the code below:

#!/bin/sh
# Script to simplify editing configuration files
#
echo "Interactive Bourne script to help edit config.txt to change settings with ease"
sleep 2
for config in config.txt
do
  if [ ! -r $config ] ; then
        echo "Cannot read $config, exiting program"
                sleep 2
                exit 0;
                else
                echo "$config found!"
                sleep 2
                fi
                done
while :
 do
 clear
 echo "======================================================================================================="
 echo "*** MENU ***"
 echo "1. Add"
 echo "2. Delete"
 echo "3. View"
 echo "Q. Quit"
 echo "======================================================================================================="
 echo -n "Enter your menu choice [1-3 or q]: "

 read userinput
 case $userinput in
 1) echo "Add option selected, ctrl k then s to save, ctrl k q to quit"
    sleep 2
    echo "Enter setting (format: ABCD=abcd): EDITOR=joe"
    read $add
   # case $add in  
    joe config.txt                                  
    echo "File changed"                 
    echo "Press any key to continue" ; read ;;
 2) echo "Delete option selected"
    echo "Press any key to continue" ; read ;;
 3) echo "View option selected"
    echo "Press any key to continue" ; read ;;
[qQ]*) exit 0 ;;
 *) echo "Please select choice 1,2,3 or q";
 echo "Press any key to continue" ; read ;;
 esac
 done


Last edited by Pits; 09-09-2007 at 01:43 AM..
# 2  
Old 09-09-2007
I finally finished it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

New user needs help with bourne shell script

This is my question, below the question is the template Write and execute a Bourne shell script called homework that will From within the script, create three background processes: a) (2 points) one that saves a long listing of your hidden files to a file named hiddenlist b) (2 points) ... (4 Replies)
Discussion started by: luislozoya
4 Replies

2. Shell Programming and Scripting

sed command not accepting variable in shell script

I am using a shell script in fedora linux. While calling to the shell I am also passing an argument (var1=0.77) like shown below sh gossip.sh var1=0.77 in the shell following command is written (which doesn't work) sed - i -e 's@prob=@prob="$var1";//@g' file.txt Actually i want the... (7 Replies)
Discussion started by: Fakhar Hassan
7 Replies

3. Shell Programming and Scripting

Accepting Input regardless of Case

Hi I am trying to get my script to accept input regardless if the person enters a or A. here is the portion of the code where I get the input. echo -n 'Please enter your choice:' # prompt user for input. read reply # read input echo case $reply in #... (2 Replies)
Discussion started by: DualPandas
2 Replies

4. Shell Programming and Scripting

Accepting user input and arguments in PERL

Hi All, Can we pass arguments while calling the perl script and as well as ask user input during execution of the script? My program is as below: I am passing arg1 and arg2 as argements to test.pl ]./test.pl arg1 arg2 Inside the test.pl I have : print "Do you want a name ? (y/n) : ";... (2 Replies)
Discussion started by: jisha
2 Replies

5. Shell Programming and Scripting

accepting input then send to file

basically im trying to promt the user to create a name for a file then send the file name to a file with the list of the file names he has created. Also i want to code if the user doesnt enter any text to just print "Default Folder" so far my code looks like: if then echo "create `$1`... (1 Reply)
Discussion started by: bravens52
1 Replies

6. Shell Programming and Scripting

Displaying default values when accepting input from user

Is there a way to display the default answer when accepting input from the user in the unix script.. e.g. ans="n" read $ans?"Enter y to continue n to exit:" altough ans contains n the message doesn't display the current contents on ans .. you get Enter y to continue n to exit: (8 Replies)
Discussion started by: flopster
8 Replies

7. UNIX for Dummies Questions & Answers

accepting input date

I how do i accept a input date in script which is lesser than a specified day? ex: to accept a date less than or equal to 100 days(from today).?:( Thanks for the help in advance.:) (1 Reply)
Discussion started by: abhi_123
1 Replies

8. Shell Programming and Scripting

Bourne Shell: Special characters Input Prevention

Environment: Sun UNIX Language: Bourne Shell Problem: I am writing a script that allows user to key in a directory. Example: /root/tmp. Since the user can key in anything he/she wants, I need to validate to make sure that he/she does not key in anything funny i.e.... (37 Replies)
Discussion started by: totziens
37 Replies

9. Shell Programming and Scripting

Accepting user input in c shell

i need to accept the user input in my c shell script before executing next command. i have the following code which ask for user input, but does not store this value. set req echo " Enter your input(Y/N)?" read req if (req = Y) echo " print $req" else echo " print $req" ... (3 Replies)
Discussion started by: skumar11
3 Replies

10. Shell Programming and Scripting

Accepting User Input

I'm just starting out with UNIX and have figured some stuff out. I just need some help with accepting user input on the command line. For instance, I created a number counter that counts down from any positive hard coded number. But, I want the commnad line line to read "Countdown 20" where 20... (1 Reply)
Discussion started by: scott78
1 Replies
Login or Register to Ask a Question