Bash: bad substitution

I was working on a bash script that uploads a file via sftp and appends a suffix to the filename. The suffix, in this specific case, should have been the date in %y-%m-%d_%H%M%S format.

I’m still a newbie with bash scripting and I used this command to upload and rename the file:

put $file $remote_dest_dir/$remote_filename${date +"%y-%m-%d_%H%M%S"}

Bash complained about a “bad substitution” on that line.

Curly braces are used for different types of parameter expansion and one of the simplest involves the expansion of the value of a variable. The date command inside the braces it’s not a valid parameter or any other expansion, so the shell complains.

I guess that what I really needed was a substitution:

$(date +"%y-%m-%d_%H%M%S")

I replaced the curly braces with regular parenthesis and everything worked like a charm.