0

I need to create the dump file name with the current date as postfix to the file name in shell script.

I tried below command in my script but that did not work.

Can any one suggest me the way :

... dump_'$(date '+%Y-%m-%d')'.txt

BACKGROUND: I feel Its not require to mention details about the script as it is not completely related to the question but still I want to give some information. My script is copying some lines from other *txt files and creating a separate dump.txt file .But I want to mention date as a postfix to the dump filename to understand the history about the file.

#!/bin/bash
# summary script

echo "Summary!"

shopt -s extglob

for f in */data/*txt; do tail -n+5 $f | head -1 | tr -d "\n"; echo " $f |"; done > dump.txt
sed -nE '/[[:blank:]][[:digit:]]?[[:digit:]]%/P' dump.txt > dump_$(date '+%Y-%m-%d').txt
wc -l dump_'$(date '+%Y-%m-%d')'.txt
Cyrus
  • 84,225
  • 14
  • 89
  • 153
jailaxmi k
  • 89
  • 3
  • 11
  • Your script doesn't actually appear to use extended globbing. Probably also figure out [When to wrap quotes around a shell variable](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Oct 27 '20 at 09:55

1 Answers1

2

You just need to remove de quotes that prevents shell interpretation:

dump_$(date '+%Y-%m-%d').txt
Juan Diego Godoy Robles
  • 14,447
  • 2
  • 38
  • 52