Unix Shell

Discussion in 'Ruby' started by Greg Johnson, Mar 2, 2006.

  1. Greg Johnson

    Greg Johnson Guest

    I'm new to RUBY, but am familar with other scripting languages, PHP,
    Perl, Wscript, etc. I'd like to be able to run items from the shell
    such as ls -l > dirlisting.txt. Just an example. Can I do this?

    I would have just used the search on these forums, but unfortuantely
    when I click Search I get "The page cannot be found". Hope they can
    get this fixed so I won't have to ask every little question.

    Thanks in advance.
    -Greg

    --
    Posted via http://www.ruby-forum.com/.
    Greg Johnson, Mar 2, 2006
    #1
    1. Advertising

  2. Greg Johnson

    James Byrne Guest

    Greg Johnson wrote:
    > I'd like to be able to run items from the shell
    > such as ls -l > dirlisting.txt. Just an example. Can I do this?
    >

    Try the Pickaxe book, the first edition is available on-line in pdf
    format. You can pass commands to the shell directly using back ticks `s
    -l > dirlisting.txt` or the %x expansion %x{echo "me, me, me..."}

    Regards,
    Jim


    --
    Posted via http://www.ruby-forum.com/.
    James Byrne, Mar 2, 2006
    #2
    1. Advertising

  3. On Fri, Mar 03, 2006 at 12:23:08AM +0900, Greg Johnson wrote:
    } I'm new to RUBY, but am familar with other scripting languages, PHP,
    } Perl, Wscript, etc. I'd like to be able to run items from the shell
    } such as ls -l > dirlisting.txt. Just an example. Can I do this?
    }
    } I would have just used the search on these forums, but unfortuantely
    } when I click Search I get "The page cannot be found". Hope they can
    } get this fixed so I won't have to ask every little question.

    There are two ways. One way:

    file_list = `ls -l`.scan(/^.*$/)[1..-1]
    file_list.each { |line|
    puts "permissions for #{line[49..-1]} are #{line[1..9]}"
    }

    The other way:

    system('ls -l > dirlisting.txt')

    } Thanks in advance.
    } -Greg
    --Greg
    Gregory Seidman, Mar 2, 2006
    #3
  4. Greg Johnson

    Greg Johnson Guest

    Thanks for the tips, they work like a charm. Does anyone know why the
    search functionality doesn't work?


    --
    Posted via http://www.ruby-forum.com/.
    Greg Johnson, Mar 2, 2006
    #4
  5. Anthony DeRobertis, Mar 2, 2006
    #5
  6. Gregory Seidman wrote:
    > On Fri, Mar 03, 2006 at 12:23:08AM +0900, Greg Johnson wrote:
    > } I'm new to RUBY, but am familar with other scripting languages, PHP,
    > } Perl, Wscript, etc. I'd like to be able to run items from the
    > shell } such as ls -l > dirlisting.txt. Just an example. Can I do
    > this? }
    > } I would have just used the search on these forums, but unfortuantely
    > } when I click Search I get "The page cannot be found". Hope they
    > can } get this fixed so I won't have to ask every little question.
    >
    > There are two ways. One way:
    >
    > file_list = `ls -l`.scan(/^.*$/)[1..-1]
    > file_list.each { |line|
    > puts "permissions for #{line[49..-1]} are #{line[1..9]}"
    > }
    >
    > The other way:
    >
    > system('ls -l > dirlisting.txt')


    There are plenty of other ways.

    system "ls", "-l"
    system "bash", "-c", "ls -l > dirlisting.txt"
    ....
    Dir["*"].each {|f| File.symlink? f and puts f}
    ....

    Cheers

    robert
    Robert Klemme, Mar 3, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,652
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    582
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,057
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    842
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. Samuel A. Falvo II
    Replies:
    0
    Views:
    472
    Samuel A. Falvo II
    Oct 8, 2008
Loading...

Share This Page