Last active
October 10, 2015 15:07
-
-
Save vangie/3709118 to your computer and use it in GitHub Desktop.
bash:变量默认值
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#直观当繁琐的写法 | |
if [ ! $1 ]; then | |
$1='default' | |
fi | |
#当变量a为null时则var=b | |
var=${a-b} | |
#当变量a为null且为空字符串时则var=b | |
var=${a:-b} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment