LoginSignup
7
9

More than 5 years have passed since last update.

bashのビルトインコマンドメモ

Last updated at Posted at 2013-05-17

bashには実体のないビルトインコマンドがあるということを知ったのでメモ

ビルトインコマンドの確認

  • type -a [対象コマンド]とすることでビルトインコマンドかどうか確認できる

  • 以下のtimeの例だとビルトインコマンド(shell keyword)だということと実体(/usr/bin/time)の2つがあることがわかる

 $ type -a time
time is a shell keyword
time is /usr/bin/time
  • おまけでll(alias)を見てみる
$ which ll
$ type -a ll
ll is aliased to `ls -alf'

ビルトインコマンドのヘルプ確認

  • help [対象コマンド]
$ help time
time: time [-p] PIPELINE
    Execute PIPELINE and print a summary of the real time, user CPU time,
    and system CPU time spent executing PIPELINE when it terminates.
    The return status is the return status of PIPELINE.  The `-p' option
    prints the timing summary in a slightly different format.  This uses
    the value of the TIMEFORMAT variable as the output format.
times: times
    Print the accumulated user and system times for processes run from
    the shell.
  • helpコマンドはビルトインコマンド
$ type -a help
help is a shell builtin

Rubyでの謎

  • なんでこうなるのかよくわかってない

  • OSXでtimeコマンドを実行

    • ビルトインコマンドが使える
1.9.3p125 :002 > `time echo`
        0.00 real         0.00 user         0.00 sys
 => "\n" 
  • AWSのEC2(AmazonLinux)でtimeコマンドを実行(/usr/bin/timeが使われている)
    • ビルトインコマンドが使えない(bash -c time echoとかすると使える)
1.9.3p327 :001 > `time echo`
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 2384maxresident)k
0inputs+0outputs (0major+189minor)pagefaults 0swaps
 => "\n" 
7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9