The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-08-2007
kprattip kprattip is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 8
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0