jdesilvio
jdesilvio

Reputation: 1854

Bash concatenate strings results in each variable within quotes

I am trying to concatenate 2 variables into a string in Bash. I have seen a lot of posts on this and for some reason they don't work for me. Here is my script which just takes a file name prefix and adds the current date to the end.

#!/bin/bash
now=$(date +”%Y%m%d”)
fname=“file”
x=$fname$now
echo $x

This results in "file""20150316" instead of the desired "file20150316".

Please help. Thanks.

Upvotes: 2

Views: 2438

Answers (1)

anubhava
anubhava

Reputation: 785058

You're using wrong quotes (unicode ones not the actual ASCII ones). Try this:

#!/bin/bash
now=$(date "+%Y%m%d")
fname="file"
x="$fname$now"
echo "$x"

Upvotes: 4

Related Questions