0

Not a duplicate of question.

I am trying to make semvar pattern (1.0.0) from array having 1,0,0 as elements and create a git tag git tag $var.

Error:- The above solution is just not working for . only, it is giving 1 0 0, space separated.

4 13 0
fatal: too many params

Error with git tag command.

Approach:-

var=$( IFS=$'.'; echo "${versionArray[*]}" )
echo $var
git tag $var  

Please suggest a better way to do it.

1 Answers1

2

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