什么冒号和破折号QUOT; - "意思是在bash [英] What does the colon dash ":-" mean in bash
本文介绍了什么冒号和破折号QUOT; - "意思是在bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的结果是一种所需;之后有点试验和错误的。我不明白什么是2: - 和3: - DO /意思。有人可以解释。
The result is the one desired; after a bit of trial and error. I don't understand what the "2:-" and "3:-" do/mean. Can someone explain.
#!/bin/bash
pid=$(ps -ef | grep java | awk ' NR ==1 {print $2}')
count=${2:-30} # defaults to 30 times
delay=${3:-10} # defaults to 10 second
mkdir $(date +"%y%m%d")
folder=$(date +"%y%m%d")
while [ $count -gt 0 ]
do
jstack $pid >./"$folder"/jstack.$(date +%H%M%S.%N)
sleep $delay
let count--
echo -n "."
done
感谢
斯泰利奥斯
推荐答案
这是一个参数扩展,它意味着的如果第三个参数为空或取消,后用什么替代它的: -
It's a parameter expansion, it means if the third argument is null or unset, replace it with what's after :-
$ x=
$ echo ${x:-1}
1
$ echo $x
$
还有另一个类似PE的分配值,如果变量为空:
There's also another similar PE that assign the value if the variable is null:
$ x=
$ echo ${x:=1}
1
$ echo $x
1
http://wiki.bash-hackers.org/syntax/pe
这篇关于什么冒号和破折号QUOT; - "意思是在bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文