Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

shell

unix

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?

EDIT

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

EDIT 2

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

like image 204
Tizianoreica Avatar asked Sep 04 '26 14:09

Tizianoreica


1 Answers

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
like image 82
Stefan Hegny Avatar answered Sep 07 '26 10:09

Stefan Hegny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!