Conversation started Nov 13, 2011 at 17:48.
Nov 13, 2011 17:48
@ScottPack Was going to ask something about passing parameters through aliases, but Google tells me it's not doable.
Ended up figuring another way to get what I wanted out of the alias, and then some, without doing that anyway.
Nov 13, 2011 18:07
Yeah, your best option is to just write a function
I went with an alias that got me a bit more information than I was wanting, but with a name that reflects that. So, it's not so bad.
alias myips="ifconfig | grep 'inet addr' | cut -d ':' -f2 | cut -d ' ' -f1"
@ScottPack What's "ew"? a five-letter alias that lists all the IPv4 addresses on the box?
(without any other fluff)
It just looks nasty.
@ScottPack I'm sure I could've done plenty worse.
Nov 13, 2011 18:19
Well, that's weird. The man page for ifconfig on Fedora 15 says that it's obsolete
Hm
What, you were hoping to find a less-emo way to do it?
I was starting to work on cleaning it up, when I noticed that.
Do you care about v6?
@ScottPack Not really at this point
ip addr | awk '/inet / {print $2}'
Bam!
Hence my use of grep 'inet addr' instead of just grep inet
Oh hey! CIDR subnet masks with that one, too!
Nov 13, 2011 18:22
Yeah, I thought that was nice too.
Didn't know about the ip addr command, and I'm only barely aware of awk.
Change that to '/inet/ to get the ipv6 addresses as well.
So... let me make sure I'm reading this right...
I ended up learning awk instead of cut. Which worked out to be nice later on when I realized that most of the time I was just piping grep into awk.
So by putting the regex directly into awk it removed a step.
You're running the ip addr command and passing it to awk obviously.
Then, awk looks for "inet " and prints the second word off of that line?
@ScottPack Ah, but that means learning regexes. I'm not quite to that level yet.
Nov 13, 2011 18:26
More specifically, prints the second field where space is the default field delimiter, but yeah.
@ScottPack By "default" I presume you mean that's alterable?
While /inet / is technically a regex, from a practical standpoint it's just a string.
Indeed.
So, let's re-write that to use ifconfig.
So, if I really didn't care about the CIDR, I'd tell awk to use ":" as a delimiter and run ifconfig instead.
ifconfig | awk '/inet addr/ {print $2}' | awk -F: '{print $2}'
@ScottPack That... doesn't look right.
Nov 13, 2011 18:29
Which part?
I mean, it obviously works...
It just seems that one of those awks is superfluous.
So you're thinking that you can just split on ':' on the first one?
@ScottPack It would seem you should be able to.
You can only split on one string at a time
So, move the -F: to the first one and see what happens
@ScottPack Yeah, that was... odd. I think there may be some order to the parameters.
And that was even weirder.
First I tried ifconfig | awk '/inet addr/ -F: '{print $2}'. That dropped me to some sort of blank command prompt.
Nov 13, 2011 18:35
Well, you got two problems there
Let me back up.
awk is a programming language used for text processing.
I tried ifconfig | awk -F: '/inet addr/ {print $2}' and it gave me the IP and the next word.
So, the line, /inet addr/ {print $2} is really just code that awk is interpreting.
Apparently, when you set a delimiter, it's ignoring the default delimiter altogether.
The -F is an argument to the application itself, not part of the code.
Right, you're changing the delimiter.
So, can you specify multiple delimiters?
Nov 13, 2011 18:37
The blank command line you got is part of bash, not awk.
@Iszi To the best of my knowledge no.
There are thousands, of people out there that know way more about awk than I do. So if one of them shows me how, I'll change my mind.
Chore time. Gotta run
Check out this page
It could be way over your head right now, or it could help you learn the kinds of things you can do.
 
Conversation ended Nov 13, 2011 at 18:39.