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

Error message in init.sh due to using == instead of = in an if #1283

Closed
chrisdsloan opened this issue May 9, 2023 · 3 comments · Fixed by #1320
Closed

Error message in init.sh due to using == instead of = in an if #1283

chrisdsloan opened this issue May 9, 2023 · 3 comments · Fixed by #1320

Comments

@chrisdsloan
Copy link

🐛 Bug description

Running the install (init.sh), it printed an error message ("sh: 139: [: x86_64: unexpected operator"). The error message is caused because == is used instead of = in the if on line 139 of init.sh.

🤔 Expected Behavior

No error message from the if comparison.

👟 Steps to reproduce

$ curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
sh: 139: [: x86_64: unexpected operator
info: downloading wasm-pack
info: successfully installed wasm-pack to `/home/cds/.cargo/bin/wasm-pack`

Here's my fix:

diff --git a/docs/_installer/init.sh b/docs/_installer/init.sh
index 91ec0af..6fb08c0 100644
--- a/docs/_installer/init.sh
+++ b/docs/_installer/init.sh
@@ -136,7 +136,7 @@ get_architecture() {
     esac
 
     # See https://github.com/rustwasm/wasm-pack/pull/1088
-    if [ "$_cputype" == "aarch64" ] && [ "$_ostype" == "apple-darwin" ]; then
+    if [ "$_cputype" = "aarch64" ] && [ "$_ostype" = "apple-darwin" ]; then
         _cputype="x86_64"
     fi
 

🌍 Your environment

I'm running on Pop!_OS 20.04 LTS on an x86 laptop. The bash version is "5.0.17(1)-release".

wasm-pack version: wasm-pack 0.11.0. The error is present in master (48177dc) as well.
rustc version: rustc 1.68.1 (8460ca823 2023-03-20)

@chrisdsloan chrisdsloan changed the title Error message in init.sh due to using == instead of = Error message in init.sh due to using == instead of = in an if May 9, 2023
@seanbright
Copy link

seanbright commented May 23, 2023

Since init.sh uses bashisms (and requests bash in the shebang), the installation instructions should instead be updated to pipe the script to bash instead of sh, e.g.:

$ curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | bash

Alternatively init.sh could be made compatible with POSIX sh and the installation instructions could remain as is.

@chrisdsloan
Copy link
Author

The existing version has "#!/bin/bash" but the double equals is the only bashism I saw, so I agree that switching the instructions to use bash in the pipe will work fine, but moving the shebang to /bin/sh and fixing the double equals seems like the best way to maintain maximum portability, I'd think.

@seanbright
Copy link

local is not POSIX.

lucashorward added a commit to lucashorward/wasm-pack that referenced this issue Aug 7, 2023
- Fixed error on line 139 - "==" was being used, whereas sh expects a "=" (and we do this correctly throughout the rest of the file). See https://www.shellcheck.net/wiki/SC3014 for more.
- Changed the use of backticks to the use of `$()` as specified in https://www.shellcheck.net/wiki/SC2006
- Changed the use of `-a` to `&&` as specified in https://www.shellcheck.net/wiki/SC2166

Closes rustwasm#1159
Closes rustwasm#1217
Closes rustwasm#1283
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants