Antonio Calì Antonio Calì - 1 year ago 226
Bash Question

Concat Variable (date) and String in shell unix - bash

I'm trying to concat a var (date) and string to have a file with current date name.

My code.

days="$(date +"%Y%m%d_%H%M")"
echo "SKIP" > ${days}_EMERGENCY.txt

but when I run, I get a file with a ? in file name, like this:

enter image description here

Am I doing something wrong?


Looking at symbol, ? stands for \r - could it be because I'm writing on notepad and then upload via ftp the .sh script?


Tried with vi on local machine - now it's also worse.
enter image description here

Answer Source

I guess your vi will have made the entire file DOS-style and so there will be another carriage return at the end of the echo statement

Try dos2unix or using an editor that allows you to change the line-ending style or

sed -i "s/$( printf '\015' )//g" yourscript
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download