0

I'm creating a simple .sh and trying to put a date(yyyymmdd) in the end of my filename

today=$(date +"%Y%m%d")
file="/nas/backup_$today.sql"
echo $file

But when I print the name, this is the result:

.sql/backup_02_10_2022

How can I keep the ".sql" in the end of the name?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • 1
    I'm not sure how this is what is being echoed. I tried on sh, bash, zsh, and ksh and they all print "/nas/backup_20220210.sql". – erip Feb 10 '22 at 21:11
  • 6
    Your script has DOS line endings; `today` ends with a carriage return. `file` *does* end with `.sql` (well, `.sql\r`), but the carriage return moves the cursor while displaying the value. – chepner Feb 10 '22 at 21:11
  • See ["Are shell scripts sensitive to encoding and line endings?"](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – Gordon Davisson Feb 10 '22 at 22:23

0 Answers0