Home > Blockchain >  iTerm2 "bad floating point constant" on startup
iTerm2 "bad floating point constant" on startup

Time:11-21

I am not sure whether this is the correct place to post this question.

I recently installed iTerm 2 together with shell integration. However, I am getting a constant error/warning on the start up:

> /Users/usr/.iterm2_shell_integration.zsh:32: bad floating point constant

The .iterm2_shell_integration.zsh on line 32 has the following code:

ver=$(printf "%.0f" $(sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ' | sed -e 's/ //g'))
zsh: bad floating point constant

line 32 snippet

I am not sure if there is a bug or if there is something wrong with my setup.

The build version is 3.4.18 and I am running this on MacOS Ventura 13.0.1.

CodePudding user response:

The ver tries to retrieve your main OS version, in your case, it should be 13.

Try commenting line 32 and instead configure:

ver=13

Or you can fix the line yourself, there's most likely something replaced/new in MacOS 13, so try to open up a terminal and execute these commands apart from each other to see where it errors:

sw_vers
sw_vers | grep ProductVersion
sw_vers | grep ProductVersion | cut -d':' -f2
sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' '
sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ' | sed -e 's/ //g'
printf "%.0f" $(sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ' | sed -e 's/ //g')

CodePudding user response:

Adding to @KevinC suggestion:

Substituting line 32 with

ver=$(printf "%.0f" $(sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ' | cut -d'.' -f 1 | sed -e 's/ //g'))

seems to do the job. The issue is that with non-major Mac OS versions, for example 13.0.1 in this case, it tries to do the float formatting via printf "%.0f" which fails since the version number is not a float.

This may not be a solid solution but it gets the job done.

You can test this on your terminal with

printf "%.0f" $(echo some_version_number | tr -d ' ' | cut -d'.' -f 1  | sed -e 's/ //g')

for example set some_version_number to 13.0.1 or 13.0 and it should yield 13 in both cases.

  • Related