meaning of today=${1:-${today}}

what does today=${1:-${today}} mean???

I saw a script which has these two lines:
today=`date '+%y%m%d'`
today=${1:-${today}}

but both gives the same value for $today

user:/export/home/user>today=`date '+%y%m%d'`
user:/export/home/user>echo $today
120326
user:/export/home/user>today=${1:-${today}}
user:/export/home/user>echo $today
120326
user:/export/home/user>today=
user:/export/home/user>today=${1:-${today}}
user:/export/home/user>echo $today
 
user:/export/home/user>

Can someone please let me know, what actually today=${1:-${today}}
means???

If a parameter is given along with a script name while invoking it, then that parameter is considered, otherwise 'today' would contain `date +%y%m%d` .

For e.g., consider this script:

#! /bin/bash
today=`date '+%y%m%d'`
today=${1:-${today}}
echo $today

While invoking it, if you provide a parameter then variable 'today' would contain that parameter:

[user@host ~]$ ./test.sh 120331
120331

If you invoked the script without any parameters, then variable 'today' would hold today's date:

[user@host ~]$ ./test.sh
120326
1 Like

thanks a lot balaje!!!!