Mahakaal Mahakaal - 12 days ago 6
Linux Question

Filename not printing correctly with underscore "_" in 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

Answer

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

echo "$BACKUP_DESTINATION/$DATE_FOLDER/${FOLDERNAME}_$FILENAME"
Comments