私のbash関数がbash -c
。
現在のスクリプト:
#!/bin/bash
inner_function () {
echo "$1"
}
outer_function () {
bash -c "echo one; inner_function 'two'"
}
outer_function
現在の出力:
$ /tmp/test.sh
one
bash: inner_function: command not found
希望の出力:
one
two
ベストアンサー1
エクスポート:
typeset -xf inner_function
例:
#! /bin/bash
inner_function () { echo "$1"; }
outer_function () { bash -c "echo one; inner_function 'two'"; }
typeset -xf inner_function
outer_function
同じ内容を作成する別の方法はexport -f inner_function
orですdeclare -fx inner_function
。
エクスポートされたシェル関数は次のとおりです。ㅏ)bash専用の機能で、他のシェルではサポートされていません。雨)ほとんどのバグが修正されたとしても、まだ議論の余地がありますシェルショック。