12

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?

Benjamin W.
  • 38,596
  • 16
  • 96
  • 104
Mahakaal
  • 1,973
  • 9
  • 26
  • 36

2 Answers2

27

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

echo "$BACKUP_DESTINATION/$DATE_FOLDER/${FOLDERNAME}_$FILENAME"
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
-3

The problem is here : HOME_$date1.tar.gz and also here: _$FILENAME. If you use _$ then the $ is escaped.

Nevertheless you can do it with: \\_$. Then you escape the _ with the \ and the $ will be interpreted as you are used to it.

Jagger
  • 10,048
  • 7
  • 47
  • 88