My guess is the shell that executes echo $var and git tag $var uses IFS=. as well. Note var=$(IFS=.;…) cannot change the variable value in the current shell, so this unexpected IFS must have been set earlier, probably during some trials and errors.
If I'm right, the variable named var holds the expected value with dots, e.g. 1.0.0. But when you retrieve it like this
echo $var
the current IFS is used to split 1.0.0 into words, so echo receives three separate arguments: 1, 0, 0. And because echo prints its arguments with single spaces in between, you were under impression the value of var was 1 0 0.
This line
echo "$var"
doesn't rely on IFS. I expect it will show you 1.0.0.
A general solution is to double-quote variables. You should have done it anyway:
echo "$var" git tag "$var"
Also pay attention to IFS. Now it should be clear echo $IFS won't show you what the variable is; echo "$IFS" is better. In addition these methods are useful:
printf '%s' "$IFS" | hexdump -c printf '%s' "$IFS" | hexdump -C printf '%s' "$IFS" | xxd
$IFSin your main shell? If it's.thenecho $varwill print1 0 0; butecho "$var"should print1.0.0. Note for the same reasonecho $IFSis not a right way to print$IFS.IFS=.should be enough to set the value..has no special meaning under the ANSI C escaping rules.$IFSis not printing anything. @KamilMaciorowski .echo "$var"worked for me. Please put it as answer, I'll accept it.