Mohamed Ben HENDA Mohamed Ben HENDA -4 years ago 86
Bash Question

What means PREFIX=${1:-daily} in shell script

What means these declarations in bash script:

PREFIX=${1:-daily}

PROFILE=${2:-backup}

Answer Source

It means, assign the first argument (if present), else daily to variable PREFIX and assign the second argument (if present), else backup to variable PROFILE

eg:

$ cat file.sh
#!/bin/bash

PREFIX=${1:-daily}
PROFILE=${2:-backup}

echo $PREFIX
echo $PROFILE

For the following command line args given, output would be like:

$ ./file.sh
daily
backup

$ ./file.sh abc
abc
backup

$ ./file.sh abc xyz
abc
xyz
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download