3

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?

1
  • What does this have to do with STDIN? Command line arguments are not STDIN. Commented Mar 2, 2014 at 14:54

2 Answers 2

3
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 $().

Sign up to request clarification or add additional context in comments.

1 Comment

The caveat is wrong; $(command) should work in any POSIX shell. If you're on something truly ancient like SunOS 3, then maybe.
2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.