PDA

View Full Version : [SOLVED] How can i get the results of a directory listing in a bash variable?



sefs
October 9th, 2012, 11:04 AM
Hi there

How can i get the result of:

ls /sys/class/net | grep wlan

into a bash variable wX

Thanks.

greenpeace
October 9th, 2012, 11:15 AM
Hi!

Use the backtick (`) character around the command:


gp@mariachi:~$ wX=`ls /sys/class/net | grep wlan`
gp@mariachi:~$ echo $wX
wlan0

hope that helps

DarkAmbient
October 9th, 2012, 11:16 AM
wX=`ls /sys/class/net | grep wlan`

edit: greenpeace was a little faster =)

MG&TL
October 9th, 2012, 11:30 AM
Pedantic note: it's better to use $( ) rather than backticks: http://mywiki.wooledge.org/BashFAQ/082


As you were!

greenpeace
October 9th, 2012, 11:41 AM
Pedantic note: it's better to use $( ) rather than backticks: http://mywiki.wooledge.org/BashFAQ/082

oh cool... didn't know that one! Excellent pedantic noting, sir!

sefs
October 9th, 2012, 01:13 PM
Thanks fellas :P