From: Philip Mak Date: 2002-07-02T08:31:25+09:00 Subject: Re: Question: ruby vs. ksh On Tue, Jul 02, 2002 at 08:20:11AM +0900, David Douthitt wrote: > Why should I use (or when should I use) ruby over ksh? If you're doing something that involves a lot of shell commands and doesn't need complicated parsing, ksh might be better. Take this webpage, for example: http://lina.aaanime.net/ It is a page that shows the current status (uptime, free, df -k) of my machine. It's written in #!/bin/sh since I can directly call the status commands from that. It used to be in Perl, until I realized I was just making a bunch of system() calls anyway. > PS: How do I do mkdir -p in ruby? Maybe this: begin Dir.mkdir path rescue Errno::EEXIST # ignore error if directory exists end That simulates the "do nothing if directory already exists" part of "mkdir -p". It doesn't simulate the "make all parent directories if necessary" part, though. If you need that too, you might use path.split('/').each somehow to iterate through all the parent directories. I don't know if there's an easy one-liner that does "mkdir -p"; I'll let someone else answer that. You could system("mkdir -p #{path}") as a quick and easy hack, but make sure 'path' is secured. If a hacker can feed "; rm -rf /" to that variable, it would screw you up.