Display IP address in bash shell prompt

I have seen some other methods but this is my technique using the relatively lightweight sed:

export PS1=`/sbin/ifconfig eth0 | sed -n '0,/^s+inet addr:([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+).*$/s//1/p'`':w$ '

Or you can use whatever interface you want instead of eth0.  If left blank then it will display the first interface.

3 comments to Display IP address in bash shell prompt

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Please copy the string GQ2IH9 to the field below: