Skip to content

Instantly share code, notes, and snippets.

@vangie
Last active October 10, 2015 15:07
Show Gist options
  • Save vangie/3709118 to your computer and use it in GitHub Desktop.
Save vangie/3709118 to your computer and use it in GitHub Desktop.
bash:变量默认值
#!/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