![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Assigning output to a variable | jpmena | Shell Programming and Scripting | 3 | 03-27-2008 04:39 AM |
| Assigning output of command to a variable in shell | sankar reddy | Shell Programming and Scripting | 6 | 02-28-2008 03:01 AM |
| assigning nawk output to shell variable | user_prady | Shell Programming and Scripting | 6 | 11-29-2007 04:01 AM |
| Assigning output of command to a variable | oma04 | Shell Programming and Scripting | 5 | 06-27-2006 12:11 PM |
| Assigning a shell variable as a float | spieterman | Shell Programming and Scripting | 3 | 09-16-2002 09:02 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
assigning command output to a shell variable
I have the sql file cde.sql with the below contents:
abcdefghij abcwhendefothers sdfghj when no one else when others wwhen%others exception when others Now I want to search for the strings containing when others together and ceck whether that does not occur more than once in the file. I have a shell script file sample1 as below: #!/bin/sh x=$(basename $1) y=$(dirname $1) echo "filename: $x" echo "Dir name: $y" file_ext=${x##*.} if [ ! -f $x ]; then printf "File $x is not a valid file" exit fi if [ $file_ext = sql ] || [ $file_ext = pls ] || [ $file_ext = xml ]; then printf "This file has extension $file_ext\n"; grep -ciw 'when others' $x>when_others_exception fi Here in the if loop i have found the occurrence of when others using grep command. As of nw, i had written the o/p of that command to a file "when_others_exception". How can i assign the o/p of the grep command to any shell variable. I searched a lot on the web n documents and unable to find how do we ssign the o/p of any shell command to a shell variable. Doesn't this a very bad coding. Can any one tell me how do we assign o/p of any shell command to a shell variable. And also here i ahd written the contents to a file "when_others_exception". Can any one tell me how do we read that value and compare with any numeral. Thanks, Kiran. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|