f



Unix Shell

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/.


0
Greg
3/2/2006 3:23:08 PM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

5 Replies
649 Views

Similar Articles

[PageSpeed] 10

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/.


0
byrnejb (61)
3/2/2006 3:35:38 PM
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



0
ruby7133 (229)
3/2/2006 3:35:59 PM
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/.


0
Greg
3/2/2006 4:22:04 PM
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



0
3/2/2006 4:50:19 PM
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

0
bob.news (3807)
3/3/2006 8:21:27 AM
Reply: