Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > shell/filterライブラリ > Shell::Filterクラス
クラスの継承リスト: Shell::Filter < Enumerable < Object < Kernel < BasicObject
コマンドの実行結果はすべて Shell::Filter か、そのサブクラスのインスタンスとして返ります。
new(sh) -> Shell::Filter[permalink][rdoc]Shell::Filter クラスのインスタンスを返します。 通常このメソッドを直接使う機会は少ないでしょう。
self + filter[permalink][rdoc]執筆者募集
filter1 + filter2 は filter1の出力の後, filter2の出力を行う。
self < src -> self[permalink][rdoc]srcをフィルタの入力とする。 srcが, 文字列ならばファイルを, IOオブジェクトであれ ばそれをそのまま入力とする。
使用例
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
(sh.head("-n 30") < "/etc/passwd") > "ugo.txt"
}
self > to -> self[permalink][rdoc]toをフィルタの出力とする。 toが, 文字列ならばファイルに, IOオブジェクトであれ ばそれをそのまま出力とする。
使用例
Shell.def_system_command("tail")
sh = Shell.new
sh.transact {
(sh.tail("-n 3") < "/etc/passwd") > File.open("tail.out", "w")
#(sh.tail("-n 3") < "/etc/passwd") > "tail.out" # と同じ.
}
self >> to -> self[permalink][rdoc]toをフィルタに追加する。 toが, 文字列ならばファイルに, IOオブジェクトであれば それをそのまま出力とする。
使用例
Shell.def_system_command("tail")
sh = Shell.new
sh.transact {
(sh.tail("-n 3") < "/etc/passwd") >> "tail.out"
#(sh.tail("-n 3") < "/etc/passwd") >> File.open("tail.out", "w") # でも同じ。
}
test(command, file1, file2 = nil) -> bool | Time | Integer | nil[permalink][rdoc]self[command, file1, file2 = nil] -> bool | Time | Integer | nilKernel.#test や FileTest のメソッドに処理を委譲します。
require 'shell'
Shell.verbose = false
sh = Shell.new
begin
sh.mkdir("foo")
rescue
end
p sh[?e, "foo"] # => true
p sh[:e, "foo"] # => true
p sh["e", "foo"] # => true
p sh[:exists?, "foo"] # => true
p sh["exists?", "foo"] # => true
[SEE_ALSO] Kernel.#test, FileTest
append(to, filter) -> Shell::AppendFile | Shell::AppendIO[permalink][rdoc][TODO]
atime(filename) -> Time[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.atime
basename(filename, suffix = "") -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.basename
blockdev?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#blockdev?
cat(*files) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
chardev?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#chardev?
check_point[permalink][rdoc]finish_all_jobs[TODO]
chmod(mode, *filename) -> Integer[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.chmod
chown(owner, group, *filename) -> Integer[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.chown
concat(*jobs) -> Shell::Concat[permalink][rdoc][TODO]
ctime(filename) -> Time[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.ctime
delete(*filename) -> Integer[permalink][rdoc]rm(*filename) -> IntegerFile クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.delete
directory?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#directory?
dirname(filename) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.dirname
each(rs = nil) -> ()[permalink][rdoc]フィルタの一行ずつをblockに渡します。
使用例
sh = Shell.new
sh.cat("/etc/passwd").each { |line|
puts line
}
echo(*strings) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
executable?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#executable?
executable_real?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#executable_real?
exist?(file) -> bool[permalink][rdoc]exists?(file) -> boolFileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#exist? FileTest.#exists?
file?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#file?
find_system_command(command)[permalink][rdoc][TODO]
foreach(path = nil, &block) -> ()[permalink][rdoc]pathがファイルなら, File#foreach pathがディレクトリなら, Dir#foreach の動作をします。
使用例
require 'shell'
Shell.verbose = false
sh = Shell.new
sh.foreach("/tmp"){|f|
puts f
}
ftype(filename) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.ftype
glob(patten) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
[SEE_ALSO] Dir.[]
grpowned?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#grpowned?
identical?[permalink][rdoc][TODO]
input -> Shell::Filter | nil[permalink][rdoc]現在のフィルターを返します。
input=(filter)[permalink][rdoc]フィルターを設定します。
inspect -> String[permalink][rdoc]オブジェクトを人間が読める形式に変換した文字列を返します。
[SEE_ALSO] Object#inspect
join(*item) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.join
link(old, new) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.link
lstat(filename) -> File::Stat[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.lstat
mkdir(*path) -> Array[permalink][rdoc]Dir.mkdirと同じです。 (複数可)
使用例
require 'shell'
Shell.verbose = false
sh = Shell.new
begin
p sh.mkdir("foo") #=> ["foo"]
rescue => err
puts err
end
mtime(filename) -> Time[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.mtime
notify(*opts) { ... } -> ()[permalink][rdoc][TODO]
open(path, mode) -> File | Dir[permalink][rdoc]path がファイルなら、 File.open path がディレクトリなら、 Dir.open の動作をします。
out(dev = STDOUT, &block) -> ()[permalink][rdoc]Shell#transact を呼び出しその結果を dev に出力します。
使用例:
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
File.open("out.txt", "w"){ |fp|
sh.out(fp) {
system("ls", "-l") | head("-n 3")
}
}
owned?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#owned?
pipe?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#pipe?
readable?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#readable?
readable_real?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#readable_real?
readlink(path) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.readlink
rehash -> {}[permalink][rdoc]登録されているシステムコマンドの情報をクリアします。 通常、使うことはありません。
rename(from, to) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.rename
rmdir(*path) -> ()[permalink][rdoc]Dir.rmdirと同じです。 (複数可)
setgid?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#setgid?
setuid?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#setuid?
size(file) -> Integer[permalink][rdoc]size?(file) -> Integer | nilFileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#size FileTest.#size?
socket?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#socket?
split(pathname) -> [String][permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.split
stat(filename) -> File::Stat[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.stat
sticky?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#sticky?
symlink(old, new) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.symlink
symlink?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#symlink?
system(command, *opts) -> Shell::SystemCommand[permalink][rdoc]command を実行する.
使用例:
require 'shell'
Shell.verbose = false
sh = Shell.new
print sh.system("ls", "-l")
Shell.def_system_command("head")
sh.system("ls", "-l") | sh.head("-n 3") > STDOUT
tee(file) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
to_a -> [String][permalink][rdoc]実行結果を文字列の配列で返します。
Shell.def_system_command("wc")
sh = Shell.new
puts sh.cat("/etc/passwd").to_a
to_s -> String[permalink][rdoc]実行結果を文字列で返します。
Shell.def_system_command("wc")
sh = Shell.new
sh.transact {
puts (cat("/etc/passwd") | wc("-l")).to_s
}
transact { ... } -> object[permalink][rdoc]ブロック中で shell を self として実行します。
例:
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact{
system("ls", "-l") | head > STDOUT
# transact の中では、
# sh.system("ls", "-l") | sh.head > STDOUT と同じとなる。
}
truncate(path, length) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.truncate
unlink(path) -> self[permalink][rdoc]path がファイルなら File.unlink、path がディレクトリなら Dir.unlink の動作をします。
[SEE_ALSO] File.unlink, Dir.unlink
utime(atime, mtime, *filename) -> Integer[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.utime
world_readable?[permalink][rdoc][TODO]
world_writable?[permalink][rdoc][TODO]
writable?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#writable?
writable_real?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#writable_real?
zero?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#zero?
self | filter -> object[permalink][rdoc]パイプ結合を filter に対して行います。
使用例
Shell.def_system_command("tail")
Shell.def_system_command("head")
Shell.def_system_command("wc")
sh = Shell.new
sh.transact {
i = 1
while i <= (cat("/etc/passwd") | wc("-l")).to_s.chomp.to_i
puts (cat("/etc/passwd") | head("-n #{i}") | tail("-n 1")).to_s
i += 1
end
}