0

I was looking at some startup scripts. particularly nginx. I noticed they have a block that looks like this

nginx=${NGINX-/usr/sbin/nginx}
prog=`/bin/basename $nginx`
conffile=${CONFFILE-/etc/nginx/nginx.conf}
lockfile=${LOCKFILE-/var/lock/subsys/nginx}
pidfile=${PIDFILE-/var/run/nginx.pid}
SLEEPMSEC=${SLEEPMSEC-200000}

I was trying to figure out what the '-' does in the middle of some of the $ lines

As an experiment I wrote my own script

#NGINX="b"


f=${NGINX-/etc/nginx/nginx.conf}
echo $f

If I keep the NGINX line commented it prints /etc/nginx/nginx.conf but if I uncomment it just prints b

So my question is what is the '-' doing and why would you want to use it this way?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
ThrowsException
  • 2,586
  • 20
  • 37
  • Similarly, [What is a hyphen beside a shell variable?](http://stackoverflow.com/questions/32964357/what-is-a-hyphen-beside-a-shell-variable) – Charles Duffy May 01 '17 at 15:57
  • 2
    Actually, I'm calling [Usage of colon dash in bash](http://stackoverflow.com/questions/10390406/usage-of-colon-dash-in-bash) a proper duplicate -- the question only covers the `${var:-value}` case, but the answer covers the `${var-value}` case as well. – Charles Duffy May 01 '17 at 16:00
  • 2
    BTW, http://wiki.bash-hackers.org/syntax/pe is one of the better reference sources on parameter expansion. – Charles Duffy May 01 '17 at 16:03
  • @CharlesDuffy Thanks those were helpful as well as the wiki page you linked. – ThrowsException May 01 '17 at 16:54

0 Answers0