wildcard problems with numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wildcard problems with numbers
# 1  
Old 10-25-2011
wildcard problems with numbers

Can someone please tell me what is wrong with this shellscript? I need to use wildcards because my numbers will be random. My number will be an ip address when I get the syntax right. I would think when I run this I would get the first case and I would see this output.

Code:
VAR1 is 123
----------
Users cannot control this device.
VAR1 is 123

Unfortunately I see this output.

Code:
VAR1 is 123
----------
I like cookies
VAR1 is 123

Code:
#!/bin/bash
VAR1=123
echo VAR1 is $VAR1
echo ----------
if [ $VAR1 = [0-9][0-9][0-9] ]; then
#if [ $VAR1 = 131.247.2.211 ]; then
    echo $"Users cannot control this device." >&2
    echo VAR1 is $VAR1
    exit 1
else
    echo $"I like cookies" >&2
    echo VAR1 is $VAR1
fi

# 2  
Old 10-25-2011
The point is testing with a equality does not work if you expect variables ( 1 cannot be equal to 8...)...
But seeing what you are up to, your test would be is VAR1 a numeric value? And that can be done by:
Code:
if [ "$VAR1"  -le 256 ]
then

And I tested, it works...
Code:
/home/vbe $ var_script   
VAR1 is 123
----------
Users cannot control this device.
VAR1 is 123

# 3  
Old 10-25-2011
You need [[ to use a wildcard pattern:
Code:
if [[ $VAR1 == [0-9][0-9][0-9] ]]; then

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies

2. Shell Programming and Scripting

Wildcard in ls

Hi Experts, I want to use ls in the below form: ls -l *.{txt,TXT} (working fine) but when i am declaring a variable, VAR="*.{txt,TXT}" ls -l $VAR is not working. Please help. Thanks. (4 Replies)
Discussion started by: sugarcane
4 Replies

3. UNIX for Dummies Questions & Answers

Print numbers and associated text belonging to an interval of numbers

##### (0 Replies)
Discussion started by: lucasvs
0 Replies

4. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

5. Shell Programming and Scripting

How to use wildcard * in if?

Hi, Can anyone help me how to use * in if statement. File contains below line1:a|b|c|Apple-RED| line2:c|d|e|Apple-Green| line3:f|g|h|Orange| I need to find line by line 4th field contains 'Apple' or not. Please help me at the earliest. (6 Replies)
Discussion started by: jam_prasanna
6 Replies

6. UNIX for Advanced & Expert Users

wildcard help

Can someone please explain the wildcards in this. How is this recursive? When I put this in my terminal it recursively displayed everything. ls .* * (6 Replies)
Discussion started by: cokedude
6 Replies

7. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

8. Shell Programming and Scripting

wildcard

Hi, I have this code to search all "cif" files using wildcard for file in *.cif do grep "Uiso" $file | awk '{ print $3, $4, $5 }' > tet done I get this error "grep: *.cif: No such file or directory" Please where am I going wrong!!! Thank you in advance (6 Replies)
Discussion started by: princessotes
6 Replies

9. UNIX for Dummies Questions & Answers

seperating records with numbers from a set of numbers

I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file. I want to seperate the records which has the field 1=(any of the number from numbers... (15 Replies)
Discussion started by: Shiv@jad
15 Replies

10. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies
Login or Register to Ask a Question