Ben*_*ynn 8 io-redirection shell-script here-document
撇开使用输出是否应该转到 stderr的问题,如果您必须将下面 cat 命令的输出重定向到 stderr,您会怎么做?
function usage {
cat << " EOF_USAGE"
usage: FrameworkBuildScript --clean-all --clean-sdk-only --build-in-externals --debug-only --release-only --resources-only
--clean-all Clean all libraries before building
--clean-sdk-only Clean SDK library before building
--build-in-externals Include all libraries in the SDK library
--debug-only Build only the debug SDK framework
--release-only Build only the release SDK framework
--resources-only Build only the SDK resource bundles
Example: $0 --clean --build-in-externals
EOF_USAGE
}
Run Code Online (Sandbox Code Playgroud)
Sté*_*las 12
cat << EOF >&2
...
EOF
Run Code Online (Sandbox Code Playgroud)
或者:
cat >&2 << EOF
...
EOF
Run Code Online (Sandbox Code Playgroud)
或者:
>&2 cat << EOF
...
EOF
Run Code Online (Sandbox Code Playgroud)
或者:
usage() {
cat << EOF
...
EOF
} >&2
Run Code Online (Sandbox Code Playgroud)
function usage {
是ksh
语法。只有在 AT&T 实现中ksh
,以这种方式定义的函数的行为不同才有意义。在其他 shell 中,支持的非标准语法的行为与 Bourne/POSIXusage() {
语法相同。