Test return character.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Test return character.
# 1  
Old 12-09-2003
Test return character.

Hi,
in my korn shell I have this code:

typeset -uL1 rc
read rc?"Insert Y=Yes (default) or N=No >>"

If I press enter without value I wish to set rc=Y. This is my default.

This test: if [[ -z $rc ]] then .... Do not work.

I hope in your help. Thanks in advance.

Regards,

Giovanni
# 2  
Old 12-09-2003
I just tested this line:

read rc?"Insert Y=Yes (default) or N=No >>"; if [[ -z $rc ]]; then echo "nothing entered"; fi

and it worked fine for me. Is that a typo, or did you forget to enter a semicolon before "then" ? What kind of error are you getting?
# 3  
Old 12-09-2003
the following will assign Y to variable rc if it is null.

${rc:=Y}
# 4  
Old 12-09-2003
Hi,

If you want good robust code you should put the read
in a loop and test that you have gotten the desired
values.

Do something like the following:

#!/usr/bin/ksh

exit_read=0
while [ $exit_read = 0 ]; do
read rc?"Insert Y=Yes (default) or N=No >>"
if [[ -z $rc ]]; then
rc='y';
fi
case $rc in
y* | Y*)
exit_read=1
;;
n* | N*)
exit_read=1
;;
esac
done

echo $rc



- Finnbarr
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return the list of file name prefix with first 6 character

Good day people, Kindly advice what is the operator/command that I should try out to if I am about to return a list of prefix of my filename with first 6 character. I understand I could use sed to retrieve the first 6 charter itself. but i wonder if there is any aix command allow me to loop... (4 Replies)
Discussion started by: cielle
4 Replies

2. Programming

Test SSH but do not return password prompt

Hello forum, I want to have a function to test for passwordless SSH setup. Pretty simple. However, what I'm finding difficult is to NOT return a password prompt to screen IF it's not in place. Here's the function: check_passwordless_ssh_working() #check passed parameter, assuming it is... (4 Replies)
Discussion started by: doonan_79
4 Replies

3. UNIX for Dummies Questions & Answers

Grep to return lines not containing a character

Hello , this is my first topic cause I need your little help:( I got .txt file, and I want to find lines without letter 'a', so im writing: grep "" list.txt (list.txt is the file of course) and i have no idea why it's not working because it shows lines with a. (1 Reply)
Discussion started by: bbqtoss
1 Replies

4. Shell Programming and Scripting

Return part of string after X numbers of a character

My input strings look something like this: /dev/vs/dsk/group/vol I want to print just "group" out of the line... which is always found between the 4th and 5th "/" in the string. I figure I have to use awk, sed, or some combination to do this, but I've searched the forums and can't find... (2 Replies)
Discussion started by: ltricarico
2 Replies

5. UNIX for Dummies Questions & Answers

tcsh - test for character in string for if then

I apologize if this treads already covered ground (which I sure it must have), however I wasn't able to determine what I needed from searches. I'm trying to do detemine if a string represents a file name or not (i.e., is in the form "string.ext" or just "string"), by seeing if there's a period... (2 Replies)
Discussion started by: deepstructure
2 Replies

6. Shell Programming and Scripting

sed and character return problem

Hi, I have a problem with sed. It doesn't recognize the "\n" character. It substitudes an "n", instead of introducing a new line. This doesn't happend with print $ print "test \n \n" (it deos introduce two lines after hello) (AIX) $ sed s/bc/\n/g test.1 >test.2 $ cat test.1 bcdefg... (3 Replies)
Discussion started by: Santiago
3 Replies

7. Shell Programming and Scripting

carriage return or funky character stuck in my variables - help :)

My variables contain carriage returns... or something. Here is the line in my xml file of interest: <tmp>72</tmp> And here is the line that extracts the 72 from it: REAL=`grep '<tmp>' test.xml | sed -e 's/^ *<tmp>//' -e 's/<\/tmp>//' -re 's/(N|n|A|a|\/)/U/g'`If echo the variable it... (5 Replies)
Discussion started by: audiophile
5 Replies

8. Shell Programming and Scripting

Substituting carriage return followed by newline character - HELP

-------------------------------------------------------------------------------- Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the... (14 Replies)
Discussion started by: djkane
14 Replies

9. UNIX for Dummies Questions & Answers

Substituting carriage return follwed by newline character - HELP!

Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the line since I need to transform my file into an Excel report. Thus my idea is to... (1 Reply)
Discussion started by: djkane
1 Replies

10. Shell Programming and Scripting

How do l test for carriage return & Disk space usage

Hi, I have just written a script in /bin/bash, however, l want to test if character is a carriage return or space. Also l want my script to be able to detect my disk space and send a mail if usage is more than 90% or send an alert. Thanks Kayode (6 Replies)
Discussion started by: kayode
6 Replies
Login or Register to Ask a Question