class Shell::Echo + Shell::BuiltInCommand + Shell::Filter
クラスの継承リスト: Shell::Echo < Shell::BuiltInCommand < Shell::Filter < Enumerable < Object < Kernel < BasicObject
要約
特異メソッド
new(sh, *strings)
-
[TODO]
new(sh) -> Shell::Filter
-
Shell::Filter クラスのインスタンスを返します。 通常このメソッドを直接使う機会は少ないでしょう。
インスタンスメソッド
self + filter
-
執筆者募集
filter1 + filter2 は filter1の出力の後, filter2の出力を行う。
self < src -> self
-
srcをフィルタの入力とする。 srcが, 文字列ならばファイルを, IOオブジェクトであれ ばそれをそのまま入力とする。
- [PARAM] src:
- フィルタの入力を, 文字列もしくは,IO オブジェクトで指定します。
使用例
Shell.def_system_command("head") sh = Shell.new sh.transact { (sh.head("-n 30") < "/etc/passwd") > "ugo.txt" }
self > to -> self
-
toをフィルタの出力とする。 toが, 文字列ならばファイルに, IOオブジェクトであれ ばそれをそのまま出力とする。
- [PARAM] 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
-
toをフィルタに追加する。 toが, 文字列ならばファイルに, IOオブジェクトであれば それをそのまま出力とする。
- [PARAM] 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
self[command, file1, file2 = nil] -> bool | Time | Integer | nil
-
Kernel.#test や FileTest のメソッドに処理を委譲します。
- [PARAM] command:
- 数値、またはサイズが 1 の文字列の場合は Kernel.#test に処理委譲します。 2 文字以上の文字列の場合は FileTest のメソッドとして実行します。
- [PARAM] file1:
- 文字列でファイルへのパスを指定します。
- [PARAM] file2:
- 文字列でファイルへのパスを指定します。
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
active? -> true
-
[TODO]
append(to, filter) -> Shell::AppendFile | Shell::AppendIO
-
[TODO]
- [PARAM] to:
- 文字列か IO を指定します。
- [PARAM] filter:
- Shell::Filter のインスタンスをしています。
atime(filename) -> Time
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] File.atime
basename(filename, suffix = "") -> String
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
- [PARAM] suffix:
- サフィックスを文字列で与えます。'.*' という文字列を与えた場合、'*' はワイルドカードとして働き '.' を含まない任意の文字列にマッチします。
[SEE_ALSO] File.basename
blockdev?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#blockdev?
cat(*files) -> Shell::Filter
-
実行すると, それらを内容とする Filter オブジェクトを返します.
- [PARAM] files:
- シェルコマンド cat に与えるファイル名を文字列で指定します。
動作例
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
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#chardev?
check_point
finish_all_jobs
-
[TODO]
chmod(mode, *filename) -> Integer
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
- [PARAM] mode:
- chmod(2) と同様に整数で指定します。
[SEE_ALSO] File.chmod
chown(owner, group, *filename) -> Integer
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] owner:
- chown(2) と同様に数値で指定します。nil または -1 を指定することで、オーナーを現在の>ままにすることができます。
- [PARAM] group:
- chown(2) と同様に数値で指定します。nil または -1 を指定することで、グループを現在の>ままにすることができます。
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] File.chown
concat(*jobs) -> Shell::Concat
-
[TODO]
ctime(filename) -> Time
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] File.ctime
delete(*filename) -> Integer
rm(*filename) -> Integer
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] File.delete
directory?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#directory?
dirname(filename) -> String
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] File.dirname
each(rs = nil) {|str| ... }
-
[TODO]
each(rs = nil) -> ()
-
フィルタの一行ずつをblockに渡します。
- [PARAM] rs:
- レコードセパレーターを表す文字列を指定します。 nil ならば、Shell.record_separatorの値が使用されます。
使用例
sh = Shell.new sh.cat("/etc/passwd").each { |line| puts line }
echo(*strings) -> Shell::Filter
-
実行すると, それらを内容とする Filter オブジェクトを返します.
- [PARAM] strings:
- シェルコマンド echo に与える引数を文字列で指定します。
動作例
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
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#executable?
executable_real?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#executable_real?
exist?(file) -> bool
exists?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#exist? FileTest.#exists?
file?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#file?
find_system_command(command)
-
[TODO]
foreach(path = nil, &block) -> ()
-
pathがファイルなら, File#foreach pathがディレクトリなら, Dir#foreach の動作をします。
- [PARAM] path:
- ファイルもしくはディレクトリのパスを文字列で指定します。
使用例
require 'shell' Shell.verbose = false sh = Shell.new sh.foreach("/tmp"){|f| puts f }
ftype(filename) -> String
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] File.ftype
glob(patten) -> Shell::Filter
-
実行すると, それらを内容とする Filter オブジェクトを返します.
- [PARAM] patten:
- シェルコマンド glob に与えるパターンを指定します。 パターンの書式については、Dir.[]を参照してください。
動作例
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
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#grpowned?
identical?
-
[TODO]
input -> Shell::Filter | nil
-
現在のフィルターを返します。
input=(filter)
-
フィルターを設定します。
- [PARAM] filter:
- フィルターを指定します。
inspect -> String
-
オブジェクトを人間が読める形式に変換した文字列を返します。
[SEE_ALSO] Object#inspect
join(*item) -> String
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] item:
- 連結したいディレクトリ名やファイル名を文字列で与えます。
[SEE_ALSO] File.join
link(old, new) -> 0
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] old:
- ファイル名を表す文字列を指定します。
- [PARAM] new:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] File.link
lstat(filename) -> File::Stat
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] File.lstat
mkdir(*path) -> Array
-
Dir.mkdirと同じです。 (複数可)
- [PARAM] path:
- 作成するディレクトリ名を文字列で指定します。
- [RETURN]
- 作成するディレクトリの一覧の配列を返します。
使用例
require 'shell' Shell.verbose = false sh = Shell.new begin p sh.mkdir("foo") #=> ["foo"] rescue => err puts err end
mtime(filename) -> Time
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] File.mtime
notify(*opts) { ... } -> ()
-
[TODO]
open(path, mode) -> File | Dir
-
path がファイルなら、 File.open path がディレクトリなら、 Dir.open の動作をします。
- [PARAM] path:
- 開きたいパスを指定します。
- [PARAM] mode:
- アクセスモードを指定します。path がディレクトリの場合は無視されます。
out(dev = STDOUT, &block) -> ()
-
Shell#transact を呼び出しその結果を dev に出力します。
- [PARAM] dev:
- 出力先をIO オブジェクトなどで指定します。
- [PARAM] block:
- transact 内部で実行するシェルを指定します。
使用例:
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
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#owned?
pipe?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列か IO オブジェクトを指定します。
[SEE_ALSO] FileTest.#pipe?
readable?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#readable?
readable_real?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#readable_real?
readlink(path) -> String
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] path:
- シンボリックリンクを表す文字列を指定します。
[SEE_ALSO] File.readlink
rehash -> {}
-
登録されているシステムコマンドの情報をクリアします。 通常、使うことはありません。
rename(from, to) -> 0
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] from:
- ファイルの名前を文字列で与えます。
- [PARAM] to:
- 新しいファイル名を文字列で与えます。
[SEE_ALSO] File.rename
rmdir(*path) -> ()
-
Dir.rmdirと同じです。 (複数可)
- [PARAM] path:
- 削除するディレクトリ名を文字列で指定します。
setgid?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#setgid?
setuid?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#setuid?
size(file) -> Integer
size?(file) -> Integer | nil
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#size FileTest.#size?
socket?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#socket?
split(pathname) -> [String]
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] pathname:
- パス名を表す文字列を指定します。
[SEE_ALSO] File.split
stat(filename) -> File::Stat
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] File.stat
sticky?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#sticky?
symlink(old, new) -> 0
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] old:
- ファイル名を表す文字列を指定します。
- [PARAM] new:
- シンボリックリンクを表す文字列を指定します。
[SEE_ALSO] File.symlink
symlink?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#symlink?
system(command, *opts) -> Shell::SystemCommand
-
command を実行する.
- [PARAM] command:
- 実行するコマンドのパスを文字列で指定します。
- [PARAM] opts:
- 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
-
実行すると, それらを内容とする Filter オブジェクトを返します.
- [PARAM] file:
- シェルコマンドtee に与えるファイル名を文字列で指定します。
動作例
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]
-
実行結果を文字列の配列で返します。
Shell.def_system_command("wc") sh = Shell.new puts sh.cat("/etc/passwd").to_a
to_s -> String
-
実行結果を文字列で返します。
Shell.def_system_command("wc") sh = Shell.new sh.transact { puts (cat("/etc/passwd") | wc("-l")).to_s }
transact { ... } -> object
-
ブロック中で 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
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] path:
- パスを表す文字列を指定します。
- [PARAM] length:
- 変更したいサイズを整数で与えます。
[SEE_ALSO] File.truncate
unlink(path) -> self
-
path がファイルなら File.unlink、path がディレクトリなら Dir.unlink の動作をします。
- [PARAM] path:
- 削除したいパスを指定します。
[SEE_ALSO] File.unlink, Dir.unlink
utime(atime, mtime, *filename) -> Integer
-
File クラスにある同名のクラスメソッドと同じです.
- [PARAM] filename:
- ファイル名を表す文字列を指定します。
- [PARAM] atime:
- 最終アクセス時刻を Time か、起算時からの経過秒数を数値で指定します。
- [PARAM] utime:
- 更新時刻を Time か、起算時からの経過秒数を数値で指定します。
[SEE_ALSO] File.utime
wait? -> false
-
[TODO]
world_readable?
-
[TODO]
world_writable?
-
[TODO]
writable?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#writable?
writable_real?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#writable_real?
zero?(file) -> bool
-
FileTest モジュールにある同名のクラスメソッドと同じです.
- [PARAM] file:
- ファイル名を表す文字列を指定します。
[SEE_ALSO] FileTest.#zero?
self | filter -> object
-
パイプ結合を filter に対して行います。
- [PARAM] filter:
- Shell::Filter オブジェクトを指定します。
- [RETURN]
- 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 }