我有一个如下所示的 bash 函数:
test5() { echo $#; }
我希望能够检测到最后一个参数后面何时有空格。
例如,运行此命令(引号显示以说明空格):"test5 test"
会生成:1
,而 "test5 test "
也会生成 1
。我想检测测试后何时有空格。
谢谢!
最佳答案
无法从命令行运行。可以在脚本中工作:
#/bin/bash
test5(){
[[ $(sed ${BASH_LINENO[0]}'!d;/ $/!d' <"${BASH_SOURCE[1]}") ]] &&
echo called with trailing whitespace
echo $#;
}
test5 5 args no trailing spaces
test5 5 args three trailing spaces
test5 "1 arg no trailing spaces "
关于linux - 是否可以使用 bash 函数检测参数末尾的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54845773/