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
Search text from a file and print text and one previous line too kamranjalal Shell Programming and Scripting 6 01-06-2009 03:27 AM
Print previous, current and next line using sed ysrinu Shell Programming and Scripting 8 12-08-2008 04:05 PM
Seeing previous command JackieChan UNIX for Dummies Questions & Answers 4 06-02-2006 09:35 AM
what do one mean when referring to 'platforms'? ninelives1980 UNIX for Dummies Questions & Answers 1 04-21-2005 12:18 PM

Closed Thread
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
  #1 (permalink)  
Old 03-18-2009
bobb bobb is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
Referring from the print of the previous command

Hi,

I am a newbie in SHell Programming.
I want to ask something about referring the result of the previous command in Shell-Prog.

For example :
bnm@dsds~> ifconfig

eth0 Link encap:Ethernet HWaddr 00:0B:CD:85:A5:8A
inet addr:192.168.0.2 Bcast:192.168.0.225 Mask 255.255.255.0


bnm@dsds~> next command ???


My question is : What should i type as the next command ??? using
the if-statement below :
--------------
if [ HWaddr is equal to 00:0B:CD:85:A5 ]; then
.....
fi
--------------
so that it will refer to the HWaddr 00:0B:CD:85:A5 printed
as the result of the previous command ?


Thanks in advance.

Bob
  #2 (permalink)  
Old 03-18-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,924
There are many ways of doing what you want. Here is an example of one way
Code:
#!/usr/local/bin/bash

ifconfig eth0 > ifconfig.out
hwaddr=$(grep "HWaddr" ifconfig.out | cut -d " " -f 5)

if [ $hwaddr = "00:0B:CD:85:A5:8A" ]
then
    echo "match"
fi
  #3 (permalink)  
Old 03-18-2009
bobb bobb is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
Other Ways

Quote:
Originally Posted by fpmurphy View Post
There are many ways of doing what you want. Here is an example of one way
Code:
#!/usr/local/bin/bash

ifconfig eth0 > ifconfig.out
hwaddr=$(grep "HWaddr" ifconfig.out | cut -d " " -f 5)

if [ $hwaddr = "00:0B:CD:85:A5:8A" ]
then
    echo "match"
fi
Thank you for the answer, fpmurphy.
Could i know the other ways, please ? since i am avoiding writing the result into a file.
Then, what does "cut -d "" -f 5" mean ?

Closed Thread

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 11:54 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