This question already has an answer here:
这个问题在这里已有答案:
- Difference between single and double quotes in Bash 5 answers
Bash 5答案中单引号和双引号之间的区别
I'm trying to find a way the use a variable in this command to replace -10 with n_days var:
我试图找到一种方法,在此命令中使用变量用n_days var替换-10:
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)
1 个解决方案
#1
3
Two things:
- Declare your variable properly (there is a space in your example)
- 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)
#1
3
Two things:
- Declare your variable properly (there is a space in your example)
- 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)