简体   繁体   中英

can't read bash script

I ran into this syntax

export ts=${2:-`date "+%s"`}

I know about export and ${2} . I even understand +%s

what does it mean to add :- behind it?

googling these symbols is useless. where do you look up things like this?

The dash causes the expansion to be the value of the variable if it is defined, or the expansion of what follows if the variable is not defined.

Example:

AA=aa
echo ${AA:-11}
echo ${BB:-22}

Will produce the output:

aa
22

Because AA is defined and BB is not.

It means "If the second command line argument has not been passed to the program, use the following value":

`date "+%s"`

It is called "parameter substitution" and is documented here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM