Results 1 to 6 of 6

Thread: How can i get the results of a directory listing in a bash variable?

  1. #1
    Join Date
    Apr 2006
    Beans
    Hidden!

    How can i get the results of a directory listing in a bash variable?

    Hi there

    How can i get the result of:

    ls /sys/class/net | grep wlan

    into a bash variable wX

    Thanks.

  2. #2
    Join Date
    Feb 2008
    Beans
    251
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can i get the results of a directory listing in a bash variable?

    Hi!

    Use the backtick (`) character around the command:

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

  3. #3
    Join Date
    Aug 2008
    Location
    Sweden
    Beans
    307
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How can i get the results of a directory listing in a bash variable?

    Code:
    wX=`ls /sys/class/net | grep wlan`
    edit: greenpeace was a little faster =)
    This is my signature

  4. #4
    Join Date
    Jun 2011
    Location
    United Kingdom
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: How can i get the results of a directory listing in a bash variable?

    Pedantic note: it's better to use $( ) rather than backticks: http://mywiki.wooledge.org/BashFAQ/082


    As you were!

  5. #5
    Join Date
    Feb 2008
    Beans
    251
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can i get the results of a directory listing in a bash variable?

    Quote Originally Posted by MG&TL View Post
    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!

  6. #6
    Join Date
    Apr 2006
    Beans
    Hidden!

    Re: How can i get the results of a directory listing in a bash variable?

    Thanks fellas

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •