Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Unix Shell

Reply
Thread Tools

Unix Shell

 
 
Greg Johnson
Guest
Posts: n/a
 
      03-02-2006
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/.


 
Reply With Quote
 
 
 
 
James Byrne
Guest
Posts: n/a
 
      03-02-2006
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/.


 
Reply With Quote
 
 
 
 
Gregory Seidman
Guest
Posts: n/a
 
      03-02-2006
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



 
Reply With Quote
 
Greg Johnson
Guest
Posts: n/a
 
      03-02-2006
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/.


 
Reply With Quote
 
Anthony DeRobertis
Guest
Posts: n/a
 
      03-02-2006
Greg Johnson wrote:

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


Not sure, but this search does:
http://dir.gmane.org/gmane.comp.lang.ruby.general



 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      03-03-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using subprocess module to launch a shell shell script that itselfforks a process Samuel A. Falvo II Python 0 10-08-2008 12:43 AM
Re: How to pass shell variable to shell script from python D'Arcy J.M. Cain Python 0 02-27-2008 01:56 PM
Re: How to pass shell variable to shell script from python Gerardo Herzig Python 1 02-27-2008 12:19 PM
Re: How to pass shell variable to shell script from python Christian Heimes Python 0 02-27-2008 10:53 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM



Advertisments