I have a ruby file that I would normally run in command line as follows:
ruby file.rb YYYY-MM-DD YYYY_MM_DD
I want to write a bash script to run this file where both YYYY-MM-DD
are strings for yesterday's date.
How would I do that?
I have a ruby file that I would normally run in command line as follows:
ruby file.rb YYYY-MM-DD YYYY_MM_DD
I want to write a bash script to run this file where both YYYY-MM-DD
are strings for yesterday's date.
How would I do that?
ruby file.rb $(date -d yesterday +'%Y-%m-%d') $(date -d yesterday +'%Y_%m_%d')
Note that this will only work in bash. Other Bourne-like shells will work if you use backticks instead of $()
.
See "YYYY-MM-DD format date in shell script" to figure out how to get the date in whatever format you want.
Yesterday's date can be found as:
date -d '1 day ago' +'%Y/%m/%d'
from "How To Get Yesterday’s Date using BASH Shell Scripting".
Replace the /
with -
or _
and then pass them in to the Ruby statement.
Edit: Vote for the other guy. Their answer actually has code.