![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Korn: How to loop through a string character by character | shew01 | Shell Programming and Scripting | 10 | 12-02-2008 07:58 AM |
| Extracting a string from one file and searching the same string in other files | mohancrr | Shell Programming and Scripting | 1 | 09-19-2007 04:17 AM |
| converting character string to hex string | axes | High Level Programming | 5 | 09-20-2006 02:04 PM |
| searching for $ character | MizzGail | UNIX for Dummies Questions & Answers | 4 | 01-05-2006 11:21 PM |
| searching by string length | GADO | UNIX for Dummies Questions & Answers | 4 | 11-14-2005 06:00 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Code:
echo "string" | grep 'x' >/dev/null 2>&1 if [ "$?" -eq "0" ]; then echo "Found x in string" else echo "Couldnt find it" fi You get the idea.... Check out my hangman shell script - you can see the technique employed. I wish I had a job like your co-worker! ![]() Cheers ZB |
|
||||
|
Zazzybob,
I had the same probelm as turbulence's co-worker...and ur solution really worked.. but can u please explain the idea behind ur solution? i didnt get what is the significance of /dev/null there in the code? thanks sirisha |
|
||||
|
vino,
i am afraid if i understand what u suggested. Your explantion of how grep works and thereby comparing the exit status of grep to detect the presence of a letter in the string is understood, but i didnt quite follow two aspects: 1. why is there a /dev/null in his piece of code? 2. How are achieving the same without a grep in your solution? can you please take efforts to elaborate? Thanks a ton again, Sirisha |
|
|||||
|
Quote:
See this Code:
[/tmp]$ cat xyz maroon pink yellow [/tmp]$ grep pink xyz pink [/tmp]$ echo $? 0 [/tmp]$ grep pink xyz 1> /dev/null [/tmp]$ echo $? 0 [/tmp]$ grep pink xyz.file 1> /dev/null grep: xyz.file: No such file or directory [/tmp]$ echo $? 2 [/tmp]$ grep pink xyz.file 1> /dev/null 2> /dev/null [/tmp]$ echo $? 2 [/tmp]$ grep pink xyz 1> /dev/null 2> /dev/null [/tmp]$ echo $? 0 [/tmp]$ That should explain the role of /dev/null. If not, read it from up the wiki site. Quote:
See this thread - String extraction from user input - sh vino Last edited by vino; 01-11-2006 at 08:46 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|