Writing Script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing Script?
# 1  
Old 12-14-2003
Writing Script?

Anyone have an example of a simple shell script that solicits a (Y)es or (N)o response from the user. If the response is 'Y' display a message on the screen that thanks the user for the positive response. If the response is 'N' display a message that thanks the user for the negative response. If the answer is anything else, redisplay the question.
# 2  
Old 12-14-2003
see my response to one of your other posts, i already prototyped this.
Code:
while ($user_input == "")
if ($user_input == ("y" || "Y"))
do something
else if ($user_input == ("n" || "N"))
do something
else
do something else

again the syntax is different for different languages.

that while loop makes sure that some user input is entered, and that last else can be used to make sure that they enter either y Y n or N.
you could put it in a function, bash supports this:
Code:
userinput()
{
while ... 
if ...
else if ...
else
do 
userinput()
}

make sure if you use my example that you check everything out for you self as i have just typed this up and it is only a general idea of what you can do.

edit: a number of your posts in Q&A for dummies really belong in shell scripting....it really helps if you pay attention to the different forums we have here. it makes the site more navigable and information easier to access for others.
# 3  
Old 01-07-2004
nordsk hensk, would you know what command i can use to prompt the user for input? I want to prompt a user for their password and cant figure out how.
# 4  
Old 01-07-2004
You can accomplish this by using the echo & read commands though keep in mind its not at all secure!

Code:
echo "Please Enter Your Checking Account Number: \c"
read ACCOUNT_NUMBER

echo "The account number you entered was: $ACCOUNT_NUMBER"

# 5  
Old 01-07-2004
Great! its working almost perfectly. the only problem is that its printing the "\c". How do i get that to not print?
# 6  
Old 01-07-2004
remove the "\c" character! What shell are you using? that sequence should cause the cursor to remain on line. i.e. not print a new line.
# 7  
Old 01-07-2004
Ok. I thought it did something so I wasn't removing it. But it doesnt stop the terminal from going to the next line.I'm using macosx 10.2.2 jaguar with a tcsh shell. do you know how i could accomplish what "\c" is supposed to do in my shell, because it doesnt seem to work?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Help with script writing?

I am new for script writing. I have a file named as name.dat and contain numbers with different rows and columns. I want to sum numbers at one row with that of at another row; like row1 + row101 + row 201, with corresponding columns. Any one can help me to write a script for this operation. ... (1 Reply)
Discussion started by: kumnegert
1 Replies

2. Shell Programming and Scripting

I need help writing this script

:wall: Can't seem to figure out how to fix this please help its not starting over like I would like it to When I enter in "Date" or "Time" nothing comes Also if you can tell me the commands for the other 3 stuff that would be much appreciated #!/bin/bash clear while ; do echo... (8 Replies)
Discussion started by: nowruzr
8 Replies

3. Shell Programming and Scripting

Help in writing script

i need some help in donig some actions on files in a library. i want to get the n last files, and print to the screen their name, date, and how many times a specific string appears in each file.. how can i do this..?... (6 Replies)
Discussion started by: eee
6 Replies

4. Red Hat

writing a script

Dear Madam/Sir Who can help me with writing a script doing the following? 1- Read names of files (only files with special name format let say initially they have the same file name start like TT*) 2- Then create an empty files with the same names have been read in step one but with extension... (1 Reply)
Discussion started by: m.nageeb
1 Replies

5. Shell Programming and Scripting

Please help me in writing my script

hello all, I have a script, used to search for the strings from the set of 5 similar pattern file from the log dir. So here it goes . The input parameter is a part of the file name. When during the script execution, the script should parse the input parameter to original file's with the same... (0 Replies)
Discussion started by: baraghun
0 Replies

6. Shell Programming and Scripting

Help me in writing the script

Hi, I have written a script which converts a give hexdecimal value to binary value in perl. But now, the problem is I should read every bit of it ( if its 10101010, i should read the value in each position and if the value in that position is 1 i should print a string and should exit if its... (1 Reply)
Discussion started by: prakashreddy
1 Replies

7. UNIX for Dummies Questions & Answers

Need help writing this script

Here is the script I am trying to write along with my answer I wrote. Please help me understand why it doesn't work. Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the file exists, prompt the user for... (1 Reply)
Discussion started by: wiggles
1 Replies

8. Shell Programming and Scripting

help writing script

hi all i am having a file(a fixed length file) of 28 bytes.The file has account number from 5th place to next 16 digits. the file looks like below, 58331600563588885696ACXT5263 58331600563588885697ACXT5263 58331600563588885698ACXT5263 i want to write a script which will extract the... (8 Replies)
Discussion started by: dr46014
8 Replies

9. UNIX for Dummies Questions & Answers

help for writing a script

Hi, I need help writing a unix script to change the time in the server automatically when it reaches a specified time. Only on the 14th of april, when the time becomes midnight (00:00:00), I need the server to change the time automatically to 23:30:00 and start working on as usual with a... (2 Replies)
Discussion started by: amodha
2 Replies

10. Shell Programming and Scripting

need help writing a script

Hello everyone. Well, I will get right to the point. I am new to Perl and trying to learn it as much as I can. I have been assigned the task of writing a perl script to extract information from firewall logs. Like I said, I am new to Perl and I am having a tough time because I think what I am... (3 Replies)
Discussion started by: tarballed
3 Replies
Login or Register to Ask a Question