Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Looking at the file /etc/rc.d/init.d/functions, I can see the following is declaring a number of variables as local variables. However, why are the variables killlevel and pid_file have an equal sign after them?

killproc() {
        local RC killlevel= base pid pid_file= delay try

I'm also seeing the following syntaxes ... Any idea what ${1##*/} or ${2:-} bits are for?

__pids_var_run() {
        local base=${1##*/}
        local pid_file=${2:-/var/run/$base.pid}
share|improve this question

migrated from serverfault.com Jan 26 '14 at 5:36

This question came from our site for system and network administrators.

up vote 2 down vote accepted

These are known as parameter expansion,which is advance syntax of Shell scripting

  1. ${2:-/var/run/$base.pid} is example of

    ${VAR :-default }

    This will result in $VAR unless VAR is unset or null, in which case it will result in default. In given script, if ${2} is not set, then default value /var/run/$base.pid is taken

  2. base=${1##*/} is example of


    You can strip $var as per given pattern from front of $var if f=/etc/resolv.conf then, echo ${f#/etc/} will remove /etc/ part and get a filename only


# This will return etc/httpd/httpd.conf
echo ${f#*/}  
# This will return httpd.conf
echo ${f##*/}

Single # is non-greedy whereas, double # is greedy approach of matching expression.

share|improve this answer
Thanks. I was testing it out and appears to be coming to the same conclusion but it's good to have someone verifying it. Just to be clear, base=${1##*/} means strip from the character "#" (there is a second #) and any repetition of it (due to the *) until the character "/"? – user192702 Jan 26 '14 at 6:33
${var#pattern} will remove from shortest front pattern and ${var##pattern} will remove from longest front pattern. – Abhijeet Kasurde Jan 26 '14 at 6:36
Okay can you give me an example just to be clear? I'm not following. Sorry. – user192702 Jan 26 '14 at 6:38
Also see following link for Parameter Exapsion -gnu.org/software/bash/manual/… – Abhijeet Kasurde Jan 26 '14 at 7:21
@AbhijeetKasurde I edited your post. One typo, but primarily formatting of the enumeration as I suspected you did not know how to indent the code under de standard enumeration syntax on this site. From reading I was not sure if you would wanted the sentence "You can strip..." to be indented under 2. as well, turn that back if you don't want it like that. – Anthon Jan 26 '14 at 7:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.