I have observed that when I create a directory using a variable myvar=2099-100 mkdir $myvar && echo "done", bash adds a whitespace at the end of the directory name. The issue I have here is that this behavior seems to be very inconsistent.
If I run mkdir $myvar&& echo "done" the whitespace disappears.
If I run mkdir ${myvar} && echo "done" the whitespace disappears.
The inconsistency lies in the fact that if I create the directory without whitespace at the end once, then I can't reproduce the issue. Running the same command that would create a directory with a whitespace does create it without it at the end.
So there are two questions:
What is the best practice when creating directories using bash. Should variable assignment contain quotes?
What is the correct way of referencing the variable when running mkdir (is it ${var} notation?)?
Why is bash adding whitespace when running mkdir $var && but not adding them when mkdir $var (I guess it has to do with expansion)?
Why after creating directory without a whitespace I can't reproduce creation with a whitespace? Is the expanded variable cached somewhere?