Using wget, I need to download a file whose URL contains the year. How can I embed the current 4-digit year (at the time of running the command, e.g. 2015)? For example, what would the command currentyear
be in
wget "http://example.com/data-$(currentyear).txt"
What would be the corresponding command if I'd need the two-digit year (e.g. 15 for 2015)?
%D – Display date as mm/dd/yy. %Y – Year (e.g., 2020)
To get current date and time in Bash script, use date command. date command returns current date and time with the current timezone set in the system.
If you need the 2-digit year, you can simply use date +%y . Useful also to note that in Linux, the various options for date format can be found with man date , whereas in FreeBSD and other BSDs including OSX, you can see them with man strftime .
You can simply use the date
command as date +%Y
:
wget "http://example.com/data-$(date +%Y).txt"
If you need the 2-digit year, you can simply use date +%y
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With