Add tags

Add tags to the following comment

bashやPOSIX-shでは、外部コマンドや内部コマンドよりシェル関数が優先して呼ばれます。いっぽう、commandコマンドを使うことにより、シェル関数を省いて外部コマンドや内部コマンドを呼べます。

これを組み合わせると、下のコードのようにして、外部コマンドをシェル関数でフックできます。

ただし、シェル関数はこの方法ではフックできません。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
ls() {
    # before
    echo '***** start *****'

    # command itself
    command ls "$@"
    local result=$?

    # after
    echo '***** end *****'

    return $result
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...