[英]Is it possible to detect a space at the end of an argument with a bash function?
我有一個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 "
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.