0

I'm trying to find a way the use a variable in this command to replace -10 with n_days var:

   n_days= -10
   date_prefix=$(date -d '-10 day' +%Y/%m/%d)

I tried this way but it didn't work:

   date_prefix=$(date -d '${n_days} day' +%Y/%m/%d)
2

1 Answer 1

7

Two things:

  1. Declare your variable properly (there is a space in your example)
  2. Use double quotes in place of single quotes to allow the variable to be interpolated

So:

n_days=-10
date_prefix=$(date -d "$n_days day" +%Y/%m/%d)
Sign up to request clarification or add additional context in comments.

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.