If ENV_FILE
is not already set, you can use this:
echo > "${ENV_FILE:=./.projects.env}"
Note: if ENV_FILE
is already set to a non-null value, this will leave it unchanged and use its existing value. From the Parameter Expansion section of the bash man page:
${parameter:=word}
Assign Default Values. If parameter
is unset or null, the expansion of word
is assigned to parameter
. The value of
parameter
is then substituted. Positional parameters and special
parameters may not be assigned to in this way.
BTW, using echo
this way will not fully erase the file, it'll replace its contents with a newline (essentially, a single blank line). For a truly empty file, just don't use any command:
> "${ENV_FILE:=./.projects.env}"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…