|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | 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. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Do I need an array here?
I am still really foggy on how to make an array work for me.... I need to take the results of one command, and split it, then do another command on each result. For example: Code:
# list all interfaces that are "up" ifconfig -l -u # Let's say I get this as a result: lo0 en0 en1 #I need to then do this (for any item listed from the previous command): ipconfig getifaddr lo0 ipconfig getifaddr en0 ipconfig getifaddr en1 # And I need each interface listed separately when all is said and done. Like this: lo0 127.0.0.1 en0 10.0.0.1 en1 23.45.67.89 Thanks! |
| Sponsored Links |
|
|
|
||||
|
Quote:
Code:
#!/bin/ksh
for if in $(ifconfig -l -u | grep 'lo0')
do
echo "${if} $(ipconfig getifaddr ${if})"
doneQuote:
[my ifconfig is different - on Solaris - you'll have provide output of every command in your environment] |
|
|||
|
Yep, the grep (or grep -v) doesn't work, not sure why. As far as being on their own line, they are. The only problem is however, that I was trying to put the whole statment into a variable, like this: Code:
interfaces=`(for if in $(ifconfig -l -u)
do
echo "${if} $(ipconfig getifaddr ${if})"
done)`I'm not too worried about getting rid of the lo0 if I can get each result into variables, so I can use each one separately. Code:
# here's the result from your code: get if addr lo0 failed, (os/kern) failure lo0 en0 205.139.21.89 en1 10.0.1.25 # Now I need to be able assign each line to a variable, so ultimately I get something like this: Ethernet: 205.139.21.89 Airport: 10.0.1.25 |
![]() |
| Bookmarks |
| Tags |
| grep or |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array inside an array | manas_ranjan | UNIX for Advanced & Expert Users | 5 | 06-10-2008 03:25 PM |
| array | ccp | Shell Programming and Scripting | 3 | 02-26-2008 03:19 AM |
| I need help with an array! | djsal | Shell Programming and Scripting | 1 | 11-28-2007 11:26 AM |
| create array holding characters from sring then echo array. | rorey_breaker | Shell Programming and Scripting | 5 | 09-28-2007 09:42 AM |
| array in awk | asal_email2 | Shell Programming and Scripting | 5 | 06-13-2005 08:25 AM |