Double condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Double condition
# 1  
Old 07-29-2011
Double condition

I trying to prevent user from entering empty string and alphabet, but i can do only on of either one cannot seem to make a double condition =.= Any one can help me?? Thank in advance

Code:
	
while expr "$sold" : "[a-z]*" > /dev/null ;	#check for int
do
echo "Number only!"
echo "No. of copies sold  : "
read sold
done

Code:
	
while [ "$sold" = "" ]
do
echo "Error! Please enter a value!"
echo "value : "
read sold
done

# 2  
Old 07-29-2011
Code:
if `echo $sold` | grep -vq '^[0-9][0-9]*$'  || test -z "$author; then
  echo 'not number in $old or zero length $author" >&2
fi

# 3  
Old 07-29-2011
Erm yazu yours code have the same problem as my, i do not know why but it seem like every time there double condition it will alway have interpretation problem for shell. My code can also work stand along as in with one condition by itself it can work but when i join them up problem occur =.=
# 4  
Old 07-29-2011
What shell?
In dash (posix shell) this code works fine.
# 5  
Old 07-29-2011
Code:
menu.sh: line 260: syntax error near unexpected token `fi'
menu.sh: line 260: `fi '

i also using dash(posix shell)

Last edited by radoulov; 07-29-2011 at 12:40 PM.. Reason: Code tags, please!
# 6  
Old 07-29-2011
You could try something like this (the code accepts only integers):

Code:
while printf 'Number of copies sold: '; do
  read sold
  case $sold in
      ( *[!0-9]*|"" ) 
	    printf >&2 'Invalid input: %s\n' "$sold"  ;;
      ( * ) 
	    break                                     ;;	
  esac
done

# proceed with the value of $sold here ...

# 7  
Old 07-29-2011
Wow radoulov this work like charm can i ask you something i am actually very new to shell. Why when you set a condition for it to check number you put wild card symptom in front and behind

Last edited by GQiang; 07-29-2011 at 11:44 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

2. Shell Programming and Scripting

Replacing Double Quote in Double Quote incsv file

Hi All , We have source data file as csv file and since data could contain commas ,each attribute is quoted into double quotes.However problem is that some of the attributa data also contain double quotes which is converted to double double quote while creating csv file XLs data : ... (2 Replies)
Discussion started by: Shalini Badal
2 Replies

3. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

4. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

5. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

Replace double double quotes using AWK/SED

Hi, I have data as "01/22/97-"aaaaaaaaaaaaaaaaa""aaa""aabbbbbbbbcccccc""zbcd""dddddddddeeeeeeeeefffffff" I want to remove only the Consequitive double quotes and not the one which occurs single. My O/P must be ... (2 Replies)
Discussion started by: Bhuvaneswari
2 Replies

7. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

8. Shell Programming and Scripting

if condition

Hi how to write this: if then usage fi thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

9. Programming

double pow (double x, double y) -- problems

This is the code and I'm wondering why line 14: a = ... and line 16: b = ... is wrong. This is the first time I've tried to use this. Please help me. #include <stdio.h> #include <math.h> // The link and how the double pow is used. // // http://www.nextdawn.nl/c-reference/pow.php //... (2 Replies)
Discussion started by: pwanda
2 Replies

10. UNIX for Dummies Questions & Answers

if condition

suppose a name is read how to check whether the name contains only alphabets and space not non-alphabetic characters and special characters (5 Replies)
Discussion started by: manisha_agrawal
5 Replies
Login or Register to Ask a Question