Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use POSIX sed to upgrade version of spaceship #430

Merged

Conversation

salmanulfarzy
Copy link
Member

sed -i isn't POSIX compliant and behaves differently on BSD sed and GNU sed.

BSD sed with -i expects an extension after space. While this extension is optional on GNU sed and must be on the same argument without any intervening space. This breaks cross compatibility of script.

# BSD sed
sed -i '' -e "s/SPACESHIP_VERSION='.*'/SPACESHIP_VERSION='$new_version'/g" $filename

# GNU sed
sed -i'' -e "s/SPACESHIP_VERSION='.*'/SPACESHIP_VERSION='$new_version'/g" $filename

We could either use perl for in-place file editing or do what sed does behind the screens.

command perl -i -pe "s/SPACESHIP_VERSION='.*'/SPACESHIP_VERSION='$new_version'/g" $filename
sed -e "s/SPACESHIP_VERSION='.*'/SPACESHIP_VERSION='$new_version'/g" "$filename" >"$filename.bak"
mv -- "$filename.bak" "$filename"

Also affects uninstall script,

https://github.com/denysdovhan/spaceship-prompt/blob/fbe6ec5f090baa696b884228b4063c874b8c3a1a/scripts/uninstall.sh#L83-L88

sed -i isn't POSIX compliant and behaves differently on BSD and GNU
flavours of sed

BSD sed -i expects an extension after space. While this extension
is optional on GNU sed and must be on the same argument without any
intervening space. This breaks cross compatibility of script.
@salmanulfarzy salmanulfarzy added the bug Bug related to code base, behavior, displaying, etc. label Apr 27, 2018
@salmanulfarzy salmanulfarzy self-assigned this Apr 27, 2018
@salmanulfarzy salmanulfarzy changed the title Use perl to upgrade version in spaceship Use POSIX sed to upgrade version of spaceship Sep 28, 2018
@salmanulfarzy salmanulfarzy merged commit 0cacfad into spaceship-prompt:master Sep 28, 2018
@salmanulfarzy salmanulfarzy deleted the fix-vesion-upgrade branch September 28, 2018 13:39
dedene pushed a commit to zenjoy/spaceship-prompt that referenced this pull request Feb 24, 2019
`sed -i` isn't POSIX compliant and behaves differently on BSD `sed` and GNU `sed`.

BSD `sed` with `-i` expects an extension after space. While this extension is optional on GNU `sed` and must be on the same argument without any intervening space. This breaks cross compatibility of script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug related to code base, behavior, displaying, etc.
Development

Successfully merging this pull request may close these issues.

None yet

2 participants