2

This is the file name in question OD_Orders_2019-02-19.csv

I am trying to create a bash script to read into files with yesterday's date on the file name while retaining the rest of the files name. I would like for $y to equal the name of the file with a formula output with the exact date in the middle. So far this is what I have:

To get yesterday's date in the correct format, I made x:

x="date -d yesterday +%Y-%m-%d"

y="OD_Orders_$x.csv"

This issue with this is that the results when I do a echo $y gives me this: OD_Orders_date -d yesterday +%Y-%m-%d.csv

I need to show the value of $x when echo $y correctly without it showing the formula. I need $y to input the filename with yesterday's date in the correct format because I want to use it more later on within this script.

1 Answer 1

2

You need to use command substitution $( ... ) to substitute the output of the command instead of the command itself:

x="$(date -d yesterday +%Y-%m-%d)"
y="OD_Orders_${x}.csv"

Which of course could be simplified to:

y="OD_Orders_$(date -d yesterday +%Y-%m-%d).csv"
1
  • You Sir are the MAN! Thank you very much! I was up all night for hours and couldn't solve this. Commented Feb 20, 2019 at 15:36

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.