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
IFS is used to split
1.0.0 into words, so
echo receives three separate arguments:
0. And because
echo prints its arguments with single spaces in between, you were under impression the value of
1 0 0.
doesn't rely on
IFS. I expect it will show you
A general solution is to double-quote variables. You should have done it anyway:
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