if statement to match *


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers if statement to match *
# 1  
Old 09-20-2006
if statement to match *

Hi

I have a script like

read i
if [ $i -eq "*" ]
then
echo bingo
fi

I want to enter the if block if i is equal to *
The same doesn't happen , when I input * the script fails with error "[: too many arguments"

I know it is very basic , but still Could any one help me out with the issue

Thanks..Siva
# 2  
Old 09-20-2006
use this
Code:
read i
if [ "$i" = "*" ]
then
echo bingo
fi

if you dont put quotes around $i and if the input is * it will be expanded to all the files in the current directory.
# 3  
Old 09-20-2006
Code:
if [ "$i" = '*' ]

# 4  
Old 09-20-2006
Thanks Anubu

It works fine now
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

4. Shell Programming and Scripting

if then else; no variable match but statement executes anyway.

My first then statement is executing even though there is no match between the variables. each subsequent if then statement is also executing. Why do they execute when there is no match in the dates? yr=`date +%y` date1=12-31-$yr date=`date +%m-%d-%y` set -vx if ; ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies

5. Shell Programming and Scripting

script to match statement from a file

All, I am trying to write a script which will match the statement from one log file and then proceed for other commands mention in the script. for my application, backup is schedule to run every day at particular time and creats a log file "/var/adm/backuplog". if backup completes then... (2 Replies)
Discussion started by: anshu ranjan
2 Replies

6. Shell Programming and Scripting

trying to find match from multiple string if statement

I'm trying to create what (should be) a simple bash script that will pull computer name and use that info to bind to one of three servers. Is there any way to do this without having a text file with the names of the servers and associated computer names? (5 Replies)
Discussion started by: jacobsbigbro1
5 Replies

7. Shell Programming and Scripting

awk pattern match and search in single statement

Hi All, I am trying to alter all lines between EXEC SQL and END-EXEC that have an INCLUDE in them. The following code search="INCLUDE " cp -f ${WORK}/$file.in ${WORK}/$file.wrk2 for item in `echo $search `; do > ${WORK}/$file.wrk1 awk -vITEM="$item" '{ if ( $0... (3 Replies)
Discussion started by: Bruble
3 Replies

8. Shell Programming and Scripting

awk statement to match all lines starting with "#"

Looking for awk statement that will match all lines starting with "# " if ( $1 == \^"#" ) Input file: # of the server. If you would like to set these, please take out the # pound (#) sign in front of one or all severities and set it equal to # severity desired. For example, FATAL=3 #... (2 Replies)
Discussion started by: Arsenalman
2 Replies

9. Shell Programming and Scripting

How to match the last XML extension by using Case statement

Hi All, I have a status.txt file which contains following three files. 1.xml 2.xml 3.xml Now i have written a shell script 1.sh which contains the following cat status.txt | while read filename do echo $filename case "$filename" in xml) echo "running 1.xml" ;; ... (3 Replies)
Discussion started by: sunitachoudhury
3 Replies

10. UNIX for Dummies Questions & Answers

Regex in if-then-else statement to match strings

hello I want to do a pattern match for string in the if statement, but I am not sure how to use regex inside the if statement. I am looking for something like this: if {2,3} ]; then ..... .... ... fi (7 Replies)
Discussion started by: rakeshou
7 Replies
Login or Register to Ask a Question