Need help using % or like option in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help using % or like option in shell script
# 8  
Old 06-14-2010
Quote:
Originally Posted by alister
A couple of observations regarding this code:

1. The -n operator takes only one operand. If $a contains any IFS whitespace, the unquoted command substitution will result in more than one word and a syntax error. Since we don't know for certain anything about the range of possible values for $a, this unquoted version might be buggy. It also wouldn't hurt to double quote "$a" within the command substitution.

2. You could simplify your approach to use grep's exit status directly:
Code:
if echo "$a" | grep -q '20100614'; then

Regards,
Alister
Alister ,
I tried the above code but its showing another error
Code:
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .
try again
efmsdapp:/export/home/hut$ help grep
ERROR: Key 'grep' not found (he1)

Here is the code I used

Code:
a=21345zef
b=21345
if echo "$a" | grep -q '21345'; then
echo 'eureka'
else
echo 'try again'
fi

# 9  
Old 06-14-2010
Instead of...
Code:
grep -q '21345'

you could use...
Code:
grep '21345' > /dev/null

This User Gave Thanks to alister For This Post:
# 10  
Old 06-14-2010
Quote:
Originally Posted by alister
Instead of...
Code:
grep -q '21345'

you could use...
Code:
grep '21345' > /dev/null


Thanks Alister,It worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Menu Driven Bash Shell Script with Default Option

Hi All, I have written a menu driven bash shell script. Current Output is as below: ------------------------------------- Main Menu ------------------------------------- Option 1 Option 2 Option 3 Option 4 Exit ===================================== Enter your... (3 Replies)
Discussion started by: kiran_j
3 Replies

2. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

3. Shell Programming and Scripting

Call one script option to other in shell script

HI Guys, My Script abc.sh 1) Checks 2) CA Scipt 3) CIA Script 0) Exit Enter Choice : Now if i select choice 2 then after finshed choice 2 wait for 40 min and run choice 3 what i can write in CA Scipt option: if then My Code : ... (3 Replies)
Discussion started by: pareshkp
3 Replies

4. UNIX for Dummies Questions & Answers

Executing a tar command with the --exclude option in a Debian shell script.

Hi All, I am trying to execute the following tar command with two --exclude options to suppress extract of the two directories specified. Do I need to single quote the directory paths ?? Many thanks for your help. The relevant code excerpt from the script is: cd /var/www/${SITE} ... (7 Replies)
Discussion started by: daveu7
7 Replies

5. UNIX for Dummies Questions & Answers

Invalid option errors running shell script

The script below fails with the following error messages: gzip: invalid option -- 'w' Try `gzip --help' for more information. mysqldump: Got errno 32 on write cp: invalid option -- 'w' Try `cp --help' for more information. rm: invalid option -- 'w' Try `rm --help' for more information. ... (1 Reply)
Discussion started by: ANNACTION
1 Replies

6. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

7. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

8. Shell Programming and Scripting

sed insert option(-i) in shell script

Hi, Please tell me how to use insert option of sed in a shell script on Solaris/AIX plateform. For example I need to insert few lines on top of every file whose name starts with say "SOL_DEL". Thanx. (2 Replies)
Discussion started by: sanjay1979
2 Replies

9. Shell Programming and Scripting

Unix Shell Script: With Menu Option

I am attempting to create a shell script with the following capaciblities: 1. Listed options to choice from 2. Use to perform awk statements 3. Print a report with the awk results My questions are 1. How do I select more than one file for option #5 and #6 2. How to I create an... (11 Replies)
Discussion started by: jroberson
11 Replies

10. Shell Programming and Scripting

Shell script "-a" option

Hi, I would like to know what exactly "-a" option does in the if conditional statement. I am sure, it is not doing the logical AND (&&) operation since it appears before the file. #!/bin/ksh for file in $* ; do if ] ; then basefile=`basename $file` cp $file... (2 Replies)
Discussion started by: royalibrahim
2 Replies
Login or Register to Ask a Question