Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > shellライブラリ
Ruby 上で sh/csh のようにコマンドの実行及びフィルタリングを手軽に行うためのライブラリです。
sh/csh の制御文は Ruby の機能を用いて実現します。
sh = Shell.cd("/tmp")
sh.mkdir "shell-test-1" unless sh.exists?("shell-test-1")
sh.cd("shell-test-1")
for dir in ["dir1", "dir3", "dir5"]
  unless sh.exists?(dir)
    sh.mkdir dir
    sh.cd(dir) do
      f = sh.open("tmpFile", "w")
      f.puts "TEST"
      f.close
    end
    print sh.pwd
  end
end
sh = Shell.cd("/tmp")
sh.transact do
  mkdir "shell-test-1" unless exists?("shell-test-1")
  cd("shell-test-1")
  for dir in ["dir1", "dir3", "dir5"]
    if !exists?(dir)
      mkdir dir
      cd(dir) do
        f = open("tmpFile", "w")
        f.print "TEST\n"
        f.close
      end
      print pwd
    end
  end
end
sh.cat("/etc/printcap") | sh.tee("tee1") > "tee2"
(sh.cat < "/etc/printcap") | sh.tee("tee11") > "tee12"
sh.cat("/etc/printcap") | sh.tee("tee1") >> "tee2"
(sh.cat < "/etc/printcap") | sh.tee("tee11") >> "tee12"
print sh.cat("/etc/passwd").head.collect {|line| /keiju/ =~ line }
| Shell | Shell オブジェクトはカレントディレクトリを持ち, コマンド実行はそこからの相対パスになります. | 
| Shell::CommandProcessor | |
| Shell::Filter | コマンドの実行結果はすべて Shell::Filter か、そのサブクラスのインスタンスとして返ります。 | 
| Shell::BuiltInCommand | クラスとして実装されている全てのビルトインコマンドのスーパークラスです。 | 
| Shell::AppendIO | |
| Shell::AppendFile | |
| Shell::Cat | |
| Shell::Concat | |
| Shell::Echo | |
| Shell::Glob | |
| Shell::Tee | |
| Shell::SystemCommand | |
| Shell::ProcessController | 
| Shell::Error | shell で使用する例外のための名前空間です。 | 
| Shell::Error::CantApplyMethod | メソッドを適用できないときに発生する例外です。 | 
| Shell::Error::CantDefine | コマンドを定義出来ないときに発生する例外です。 | 
| Shell::Error::CommandNotFound | コマンドが見つからないときに発生する例外です。 | 
| Shell::Error::DirStackEmpty | 空のディレクトリスタックから要素を取り出そうとしたときに発生する例外です。 | 
| shell/builtin-command | Shell で使用するビルトインコマンドを定義しているライブラリです。 | 
| shell/command-processor | Shell で使用可能なコマンドの大半を定義するライブラリです。 | 
| shell/error | shell で使用する例外を定義したライブラリです。 | 
| shell/filter | Shell::Filter を定義しているライブラリです。 | 
| shell/process-controller | プロセスを制御するためのクラスを定義したライブラリです。 | 
| shell/system-command |