I still cannot figure out how to get this read command to work. I want the script to ask questions when prompted, and the user to enter a response. Based on response it will continue or exit. I have not worked with this type of script before so I am almost clueless on what to do, and so far google has not proved to be a valid friend on this endeavor.
I still cannot figure out how to get this read command to work. I want the script to ask questions when prompted, and the user to enter a response. . . .
What about reading the man ksh page?
Quote:
read [ -ACprsv ] [ -d delim] [ -n n] [ [ -N n] [ [ -t timeout] [ -u unit] [ vname?prompt ] [ vname ... ]
. . .
If the -v is specified, then the value of the first vname will be used as a default value when reading from a terminal device.
. . .
If the first argument contains a ?, the remainder of this word is used as a prompt on standard error when the shell is interactive.
The -v option might not be what you want it to be...
I still cannot figure out how to get this read command to work. I want the script to ask questions when prompted, and the user to enter a response. Based on response it will continue or exit. I have not worked with this type of script before so I am almost clueless on what to do, and so far google has not proved to be a valid friend on this endeavor.
Code marked in red above is not valid for ksh (some of it isn't valid for any shell I've seen) or is using variables that have not been defined. Code marked in orange above doesn't work that way on my system; and you didn't say what system you're using. (The code I have below using the what utility should work on any Linux or UNIX system I've seen.) You look for dependencies on a utility that isn't used??? You don't look for dependencies on java and setServerJava which are used in your script. (Note that my system doesn't have setServerJava, so I had to comment out that code while I tested the following script.)
The way you were printing diagnostics for unknown options doesn't match standard getopts behavior (and doesn't work on my system). The code below seems to do what you want in a portable manner. (On some systems, what you were trying would work if you used $optopt instead of $opt. And, if you want to print a custom diagnostic, you should be able to use $OPTARG instead of $opt to get the unknown option letter.)
You have a -y option, but you don't have any code to implement it. (And if you do what it implies, you will never change the java in use because it will exit when you say y in response to the question "Is this version of Java the current version you want? [y/n]". (The code below prints a diagnostic and exits if -y is given on the command line.)
The way you test NUMBITS requires a -b option to be specified on the command line and then requires that the value be entered again later???
The following script seems to do what I was guessing you were trying to do. Hopefully it will give you some useful ideas on how to do what you really want to do...
Last edited by Don Cragun; 07-05-2013 at 06:54 PM..
Reason: Update getopts notes...
This User Gave Thanks to Don Cragun For This Post:
Reviewed with my superior, said I had to many prompts, he only wants the two. It needs to ask for instances(DONE) then ask if you want to set the java bit to current version(DONE
command line to run should be like
setServerDefaultJava -b32
or
setServerDefaultJava -b64
I need to add the setServerJava or something to functions, because it isn't switching between the 2 versions of Java, I am very confused on this. It will be run in a shell script, but in a bash environment
Hello, I want to start out by saying that I am fairly new to scripting and am looking for someone that can point me in the right direction.
Basically what I need is a way to run a interactive script that will prompt users with questions weather that be yes/no or a specific answer.. I want to be... (3 Replies)
Hi,
i am working on one automation , for that i have writing one shell program that take user input in "while read line" block. but read command is taking value that is readed by While block.
while read line; do
command 1;
command 2
echo -n "Do you want to continute > "
read rsp... (2 Replies)
I want a shell script that accepts user input simultaneously when performing other tasks. Example: A shell script should echo some messages on the console and when the user presses some keys it should respond to that action.
say, when user presses the key
A - more information should be printed... (2 Replies)
How to check the user input to be valid using shell script?
The valid input is in the format like as follows.
1. It can only have r,w,x or a hyphen and nothing else.
2. ensure the r, w, x are in the correct order.
for example: rwxr-xr-x is a valid format.
Thanks (5 Replies)
I want to create an array which can store the strings from the user input in shell script .
example :-
I want to store the 5 fruits name in a single array which the user provides . (1 Reply)
Hello
I am trying to create a user input shell scipt. The objective is user should enter the circuit number and the input is saved in a log file. If the user does not enter anything then the question should prompt it until the circuit no. is entered.
Can any one please correct the code below.... (3 Replies)
Dear All,
The sqlplus 'Accept' command is not waiting for user input when I include the command within a shell script.
Note: The 'Accept' command is working fine if I execute it in a SQLPLUS Prompt.
Please fins the below sample script which i tried.
SCRIPT:
--------
#!... (4 Replies)
Dear Friends,
I am doing a sh shell script , But I dont have any idea how to read value from user Keyboard and store them to an array .. Is it possible or not I am not also sure in sh shell script ?
EX:-
#! /bin/sh
read DATA
echo "DATA -" $DATA
echo "DATA -" $DATA
echo "DATA... (7 Replies)
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)
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:
1) echo "Add... (1 Reply)