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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting meaning of today=${1:-${today}}
# 1  
Old 03-26-2012
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

Code:
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???
# 2  
Old 03-26-2012
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:
Code:
#! /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:
Code:
[user@host ~]$ ./test.sh 120331
120331

If you invoked the script without any parameters, then variable 'today' would hold today's date:
Code:
[user@host ~]$ ./test.sh
120326

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 03-26-2012
thanks a lot balaje!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check, if date is not today

hello, in a file exist entries in date format YYYYMMDD. i want to find out, if there are dates, which isn't today's date. file: date example text 20140714 <= not today's date 20140715 <= not today's date 20140716 <= today's date my idea is to use Perderabo's datecalc ... (2 Replies)
Discussion started by: bora99
2 Replies

2. What is on Your Mind?

How Would You Like Your Loops Served Today?

Scrutinizer and i had a discussion about loops in shell scripts and you might be interested in joining in and share your experiences: i wrote an example script which basically employed the following logic: cat /some/file | while read var ; do echo var = $var # just do... (8 Replies)
Discussion started by: bakunin
8 Replies

3. Shell Programming and Scripting

Grep out only today's date

Hi, I have some log files. I've been asked to grep out error messages that have happened ONLY today. (However, the logs keep messages a long time so they have error messages going back weeks) They log details in these fields (order): Month Day Time Server message I can grep out the... (8 Replies)
Discussion started by: horhif
8 Replies

4. Shell Programming and Scripting

How to list today's files

Hi, I am trying to list names of only today's files OR say, files which are not older than 1 hour and copy them in 'list.txt' file. I know, :ls > list.txt will list all the files. But, how to list today's files? Any help will be appriciated. (4 Replies)
Discussion started by: berlin_germany
4 Replies
Login or Register to Ask a Question