File: shell.rd.ja

package info (click to toggle)
ruby1.8 1.8.7.302-2squeeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 26,640 kB
  • ctags: 38,616
  • sloc: ruby: 245,002; ansic: 144,156; yacc: 5,890; sh: 2,677; lisp: 1,626; tcl: 949; makefile: 358; sed: 129; xml: 122; awk: 36; cpp: 28; asm: 25; perl: 18; python: 6
file content (336 lines) | stat: -rw-r--r-- 7,435 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
 -- shell.rb
				$Release Version: 0.6.0 $
			   	$Revision: 11708 $
			   	$Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
			   	by Keiju ISHITSUKA(keiju@ishitsuka.com)

=begin

= Ū

rubysh/cshΤ褦˥ޥɤμ¹Եڤӥե륿󥰤ڤ˹Ԥ.
sh/cshʸrubyεǽѤƼ¸.

= ʥ饹

== Shell

Shell֥Ȥϥȥǥ쥯ȥ, ޥɼ¹ԤϤ
Хѥˤʤޤ.

--- Shell#cwd
--- Shell#dir
--- Shell#getwd
--- Shell#pwd

      ȥǥ쥯ȥ֤

--- Shell#system_path

      ޥɥѥ֤

--- Shell#umask

      umask֤

== Filter

ޥɤμ¹Է̤Ϥ٤FilterȤƤޤ. Enumerableinclude
Ƥޤ.

= ʥ᥽åɰ

== ޥ

OSΥޥɤ¹ԤˤϤޤ, ShellΥ᥽åɤȤޤ.

) ޥɤʤȤľܼ¹ԤǤShell#systemޥɤ⤢ޤ.

--- Shell.def_system_command(command, path = command)

      ShellΥ᥽åɤȤcommandϿޤ. 

      )
      Shell.def_system_command "ls"
        ls 

      Shell.def_system_command "sys_sort", "sort"
        sortޥɤsys_sortȤ

--- Shell.undef_system_command(command)

      commandޤ.

--- Shell.alias_command(ali, command, *opts) {...}

      commandalias򤷤ޤ. 

      )
        Shell.alias_command "lsC", "ls", "-CBF", "--show-control-chars"
        Shell.alias_command("lsC", "ls"){|*opts| ["-CBF", "--show-control-chars", *opts]}

--- Shell.unalias_command(ali)

      commandaliasޤ.

--- Shell.install_system_commands(pre = "sys_")

      system_pathˤƤμ¹ԲǽեShell. ᥽
      ̾ϸΥե̾ƬpreĤΤȤʤ.

== 

--- Shell.new

      ץΥȥǥ쥯ȥ򥫥ȥǥ쥯ȥȤShell
      ֥Ȥޤ.

--- Shell.cd(path)

      path򥫥ȥǥ쥯ȥȤShell֥Ȥޤ.

== ץ

--- Shell#jobs

      塼󥰤Ƥjobΰ֤.

--- Shell#kill sig, job

      job˥ʥsig

== ȥǥ쥯ȥ

--- Shell#cd(path, &block)
--- Shell#chdir

      ȥǥ쥯ȥpathˤ. ƥ졼ȤƸƤФ줿Ȥˤ
      ֥å¹Τߥȥǥ쥯ȥѹ.

--- Shell#pushd(path = nil, &block)
--- Shell#pushdir

      ȥǥ쥯ȥǥ쥯ȥꥹåˤĤ, ȥǥ쥯
      ȥpathˤ. pathά줿Ȥˤ, ȥǥ쥯ȥ
      ǥ쥯ȥꥹåΥȥåפ򴹤. ƥ졼ȤƸƤФ줿
      ˤ, ֥å¹Τpushd.

--- Shell#popd
--- Shell#popdir

      ǥ쥯ȥꥹåݥåפ, 򥫥ȥǥ쥯ȥˤ.

== ե/ǥ쥯ȥ

--- Shell#foreach(path = nil, &block)

      pathեʤ, File#foreach
      pathǥ쥯ȥʤ, Dir#foreach

--- Shell#open(path, mode)

      pathեʤ, File#open
      pathǥ쥯ȥʤ, Dir#open

--- Shell#unlink(path)

      pathեʤ, File#unlink
      pathǥ쥯ȥʤ, Dir#unlink

--- Shell#test(command, file1, file2)
--- Shell#[command, file1, file2]

      եƥȴؿtestƱ. 
      )
          sh[?e, "foo"]
          sh[:e, "foo"]
          sh["e", "foo"]
          sh[:exists?, "foo"]
          sh["exists?", "foo"]

--- Shell#mkdir(*path)

      Dir.mkdirƱ(ʣ)

--- Shell#rmdir(*path)

      Dir.rmdirƱ(ʣ)

== ޥɼ¹

--- System#system(command, *opts)

      command¹Ԥ.
      )
        print sh.system("ls", "-l")
        sh.system("ls", "-l") | sh.head > STDOUT

--- System#rehash

      ϥå夹

--- Shell#transact &block

      ֥åǤshellselfȤƼ¹Ԥ.
      )
        sh.transact{system("ls", "-l") | head > STDOUT}

--- Shell#out(dev = STDOUT, &block)

      transactƤӽФη̤dev˽Ϥ.

== ޥ

--- Shell#echo(*strings)
--- Shell#cat(*files)
--- Shell#glob(patten)
--- Shell#tee(file)

      ϼ¹Ԥ, ƤȤFilter֥Ȥ֤ޤ. 

--- Filter#each &block

      ե륿ΰԤĤblockϤ.

--- Filter#<(src)

      srcե륿ϤȤ. src, ʸʤХե, IOǤ
      Ф򤽤ΤޤϤȤ.

--- Filter#>(to)

      srcե륿νϤȤ. to, ʸʤХե, IOǤ
      Ф򤽤Τޤ޽ϤȤ.

--- Filter#>>(to)

      srcե륿ɲä. to, ʸʤХե, IOǤ
      򤽤Τޤ޽ϤȤ.

--- Filter#|(filter)

      ѥ׷

--- Filter#+(filter)

      filter1 + filter2  filter1νϤθ, filter2νϤԤ.

--- Filter#to_a
--- Filter#to_s

== ȹߥޥ

--- Shell#atime(file)
--- Shell#basename(file, *opt)
--- Shell#chmod(mode, *files)
--- Shell#chown(owner, group, *file)
--- Shell#ctime(file)
--- Shell#delete(*file)
--- Shell#dirname(file)
--- Shell#ftype(file)
--- Shell#join(*file)
--- Shell#link(file_from, file_to)
--- Shell#lstat(file)
--- Shell#mtime(file)
--- Shell#readlink(file)
--- Shell#rename(file_from, file_to)
--- Shell#split(file)
--- Shell#stat(file)
--- Shell#symlink(file_from, file_to)
--- Shell#truncate(file, length)
--- Shell#utime(atime, mtime, *file)

      File饹ˤƱ̾Υ饹᥽åɤƱǤ.

--- Shell#blockdev?(file)
--- Shell#chardev?(file)
--- Shell#directory?(file)
--- Shell#executable?(file)
--- Shell#executable_real?(file)
--- Shell#exist?(file)/Shell#exists?(file)
--- Shell#file?(file)
--- Shell#grpowned?(file)
--- Shell#owned?(file)
--- Shell#pipe?(file)
--- Shell#readable?(file)
--- Shell#readable_real?(file)
--- Shell#setgid?(file)
--- Shell#setuid?(file)
--- Shell#size(file)/Shell#size?(file)
--- Shell#socket?(file)
--- Shell#sticky?(file)
--- Shell#symlink?(file)
--- Shell#writable?(file)
--- Shell#writable_real?(file)
--- Shell#zero?(file)

      FileTest饹ˤƱ̾Υ饹᥽åɤƱǤ.

--- Shell#syscopy(filename_from, filename_to)
--- Shell#copy(filename_from, filename_to)
--- Shell#move(filename_from, filename_to)
--- Shell#compare(filename_from, filename_to)
--- Shell#safe_unlink(*filenames)
--- Shell#makedirs(*filenames)
--- Shell#install(filename_from, filename_to, mode)

      FileTools饹ˤƱ̾Υ饹᥽åɤƱǤ.

      ¾, ʲΤΤꥢƤޤ.

--- Shell#cmp	<- Shell#compare
--- Shell#mv	<- Shell#move
--- Shell#cp	<- Shell#copy
--- Shell#rm_f	<- Shell#safe_unlink
--- Shell#mkpath	<- Shell#makedirs

= ץ

== ex1

  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"]
    if !sh.exists?(dir)
      sh.mkdir dir
      sh.cd(dir) do
	f = sh.open("tmpFile", "w")
	f.print "TEST\n"
	f.close
      end
      print sh.pwd
    end
  end

== ex2

  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

== ex3

  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"

== ex4

  print sh.cat("/etc/passwd").head.collect{|l| l =~ /keiju/}

=end