Linux Can';t在bash中输入日期变量

Linux Can';t在bash中输入日期变量,linux,bash,awk,Linux,Bash,Awk,我有一个目录/user/reports,其中有许多文件,其中之一是: report.active_user.30092018.77325.csv 我需要输出为日期后的数字,即上述文件名中的77325 我创建了以下命令以从文件名中查找值: ls /user/reports | awk -F. '/report.active_user.30092018/ {print $(NF-1)}' 现在,我希望将当前日期作为变量传递到上述命令中,并获得结果: ls /user/reports | awk

我有一个目录/user/reports,其中有许多文件,其中之一是:

report.active_user.30092018.77325.csv
我需要输出为日期后的数字,即上述文件名中的77325

我创建了以下命令以从文件名中查找值:

ls /user/reports | awk -F. '/report.active_user.30092018/ {print $(NF-1)}'
现在,我希望将当前日期作为变量传递到上述命令中,并获得结果:

ls /user/reports | awk -F. '/report.active_user.$(date +'%d%m%Y')/ {print $(NF-1)}'
但是没有得到所需的输出

已尝试bash脚本:

#!/usr/bin/env bash

_date=`date +%d%m%Y`

 active=$(ls /user/reports | awk -F. '/report.active_user.${_date}/ {print $(NF-1)}')


 echo $active
但输出仍然是空白的


请帮助使用正确的语法。

正如@cyrus所说,在变量赋值中必须使用双引号,因为简单引号仅用于字符串,而不用于包含变量

Bas用例

number=10
string='I m sentence with or wihtout var $number'
echo $string
number=10
string_with_number="I m sentence with var $number"
echo $string_with_number
正确的用例

number=10
string='I m sentence with or wihtout var $number'
echo $string
number=10
string_with_number="I m sentence with var $number"
echo $string_with_number
可以使用简单引号,但不能使用所有字符串

number=10
string_with_number='I m sentence with var '$number
echo $string_with_number

您不需要awk:您可以使用shell的功能进行管理

for file in report.active_user."$(date "+%d%m%Y")"*; do
    tmp=${file%.*}      # remove the extension
    number=${tmp##*.}   # remove the prefix up to and including the last dot
    echo "$number"
done

请参见

请参见:如果要将变量从单引号中去掉,请将变量置于双引号中:
string\u with_number='I m station with var''$number'