Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filename not printing correctly with underscore "_" in Bash [duplicate]

Tags:

linux

bash

I am using this

DATE_FOLDER=$(date +"%b-%d-%a-%G")
FILENAME="HOME_$date1.tar.gz"

echo $BACKUP_DESTINATION/$DATE_FOLDER/$FOLDERNAME_$FILENAME

My output is

home/May-04-Wed-2011/HOME_May-04-0718PM-2011.tar.gz

but if I use - instead of underscore _

echo $BACKUP_DESTINATION/$DATE_FOLDER/$FOLDERNAME-$FILENAME

then my ouput is correct

/home/May-04-Wed-2011/vmware-HOME_May-04-0717PM-2011.tar.gz

Why is that?

like image 942
Mahakaal Avatar asked May 05 '11 13:05

Mahakaal


1 Answers

_ is a valid character for a variable name, and $FOLDERNAME_ doesn't exist.

echo "$BACKUP_DESTINATION/$DATE_FOLDER/${FOLDERNAME}_$FILENAME"
like image 171
Ignacio Vazquez-Abrams Avatar answered Oct 20 '22 12:10

Ignacio Vazquez-Abrams