LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-21-2007, 08:15 AM   #1
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Rep: Reputation: 15
test number within a range


I am trying to test whether a number is assigned to a variable and is it within certain range (in a single line statement).

But the below code is giving an error saying -z is an unknow operator. Any clues on how to implement or mistake i have made

Code:
[[-z "$Id"] -o [!grep -q $Id [1-8]]] && _Function1

Last edited by tostay2003; 12-21-2007 at 08:18 AM. Reason: added one more statement
 
Old 12-21-2007, 08:30 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
When using complex tests (-o or -a) you can't use the double brackets. Try somethiong like this:
Code:
[[ -z "$Id" ]] || [[ ! $(grep -q $Id [1-8]) ]] && _Function1
or:
Code:
[ -z "$Id" -o ! $(grep -q $Id [1-8]) ] && _Function1
When you do use double brackets you have to leave a space between the brackets and the enclosed code.
 
Old 12-21-2007, 08:42 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by tostay2003 View Post
I am trying to test whether a number is assigned to a variable and is it within certain range (in a single line statement).

But the below code is giving an error saying -z is an unknow operator. Any clues on how to implement or mistake i have made

Code:
[[-z "$Id"] -o [!grep -q $Id [1-8]]] && _Function1
KISS and take it step by step
Code:
id=8
case $id in 
    [1-8]) function1 ;; 
    *) echo "no";; 
esac
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script using case, based on number range kinetik Programming 7 03-13-2012 07:24 AM
Link Number out of range praveenchebolu Linux - Networking 2 05-17-2007 04:49 PM
invalid `asm': operand number out of range Annie0716 Programming 4 08-05-2004 03:57 AM
Procedure call number is out of range China Jack Linux - Networking 1 06-11-2004 11:54 AM
Procedure number out of range TY2K4 Linux - Networking 2 05-29-2004 05:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration