Double condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Double condition
# 8  
Old 07-29-2011
His code is checking for any character(s) followed by a character that is not a number, followed by any character(s). I think you've missed seeing the bang (!) which implies not 0-9:

Code:
( *[!0-9]*|"" )

So it will issue an error if the string has any character that isn't an error, or is empty.

If you miss that, then yes it is confusing.

Last edited by agama; 07-29-2011 at 11:16 PM.. Reason: clarification
This User Gave Thanks to agama For This Post:
# 9  
Old 07-29-2011
Code:
( [!0-9]|"" )

Y cant i just do this??
# 10  
Old 07-30-2011
Code:
 ( [!0-9]|"" )

will just match a single character. If the user enters "a" it will print the error, but if the user enters "aa" it will not. So, by adding the two wildcard characters, you allow it to check for any number of characters, and to match if any of them isn't a digit. So it will reject all of these: "a" "aa" and "20a".
This User Gave Thanks to agama For This Post:
# 11  
Old 07-30-2011
Thank!! shell really different from other programming language haha
If you dont mind can i ask you another double condition problem i having??

Code:
	while [ "$author" == "" -o "$title" == ""]; #User need to enter either author or title in order for search to begin
	do
	echo "Title : "
	read title
	echo "Author: "
	read author
	done

The logic confirm is correct i want the user to enter either 1 of the field, to check single field for empty string i can do it but that not what i want!! i went google research and saw ppl say must [[Type here]] i try also cannot, i try to play with the ""''`` also cannot =.=
Ya i also try with
Code:
while["$author" -eq ""] && ["$title" -eq ""]

# 12  
Old 07-30-2011
Are you using bash or Kshell?

This should work regardless:

Code:
while [ "$author" = "" -a "$title" = ""];

You want to loop when both strings are empty (and) rather than one or the other. I'm not sure that the test command (single brackets) supports the double equal (==) which you had in your sample.

If you are using Kshell or bash I think this is a bit more efficient and easier to read:
Code:
while [[ "$author" == ""  ||  "$title" == "" ]]
do
.......code here......
done

Hope this makes sense.
This User Gave Thanks to agama For This Post:
# 13  
Old 07-30-2011
Ok the 2nd 1 work thank man. Just to clear my doubt how do u know where to put the [] is there a standard way?? and also when do i use == instead of -eq.Lastly u will saying there are different shell is that right?? Different shell different writing style??
# 14  
Old 07-30-2011
Glad that worked.

There are quite a few different shells. Most of them follow the same general syntax (based on the original Bourne shell sh) The most popular are Korn Shell (ksh) and bash. While their syntax may be very similar, they do operate differently in some cases. I prefer ksh as it allows for things that bash doesn't do.

Here is a link to an article on this site that might help answer some of your questions:
Linux.com :: Korn -- an extended shell


The single bracket expression (e.g. [...]) invokes the external test command. Execute [icode]man test[\icode] for more information. It isn't as efficient as using the builtin [[...]] evaluation expressions in ksh/bash, and requires the use of -xx operators for testing strings which I find difficult to read.

As to where to bracket, it depends on what I'm trying to do, but usually I try to have the entire expression inside a single pair of brackets (single or double).
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