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

Miniconda3-latest-Linux-x86_64.sh: 494: [[: not found #10431

Closed
samuel-hunter opened this issue Dec 25, 2020 · 20 comments · Fixed by conda/constructor#599
Closed

Miniconda3-latest-Linux-x86_64.sh: 494: [[: not found #10431

samuel-hunter opened this issue Dec 25, 2020 · 20 comments · Fixed by conda/constructor#599
Labels
backlog issue has been triaged but has not been earmarked for any upcoming release severity::2 critical; broken functionality with an unacceptably complex workaround source::community catch-all for issues filed by community members type::installer indicates a request or issue pertaining to the installer

Comments

@samuel-hunter
Copy link

samuel-hunter commented Dec 25, 2020

Current Behavior

After being prompted to run conda init, The miniconda installer exits with the error [[: not found, and then continues installing:

Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
Miniconda3-latest-Linux-x86_64.sh: 494: [[: not found

Steps to Reproduce

  1. Use a Linux distribution that links /bin/sh to a shell outside bash -- Debian, for example. links it to dash.
  2. Download Miniconda3-latest-Linux-x86_64.sh from https://docs.conda.io/en/latest/miniconda.html
  3. Run it either with chmod +x Miniconda3-latest-Linux-x86_64.sh && ./Miniconda3-latest-Linux-x86_64.sh or sh Miniconda3-latest-Linux-x86_64.sh
  4. After being prompted to run conda init, answer yes.

Steps to Fix

It looks like the issue with the command is in the Installer:

# lines 494-499
        if [[ $SHELL = *zsh ]]
        then
            $PREFIX/bin/conda init zsh
        else
            $PREFIX/bin/conda init
        fi

[[, as a bash extension, is not necessarily available for all POSIX shells (as the hashbang #!/bin/sh implies). There are two solutions here:

(Preferred) Replace [[ with a case

# replace lines 494-499 with:
        case $SHELL in
            *zsh)
                $PREFIX/bin/conda init zsh
                ;;
            *)
                $PREFIX/bin/conda init
                ;;
        esac

Explicitly mark the installer as a bash script:

Replace the hashbang on line 1:

-#!/bin/sh
+#!/bin/bash

In theory this solution is easy enough for me to make a pull request instead, but I couldn't for the life of me figure out how the installer is built. acking for the code snippet in this repo shows nothing for me, and being completely new to conda, I don't know which repo out of the 37 in this GitHub organization contains the script that builds the installer. If I could find a pointer to where it is, I'd be happy to set up the pull request.

@chenghlee chenghlee added the source::community catch-all for issues filed by community members label Jan 7, 2021
@chenghlee chenghlee added the type::installer indicates a request or issue pertaining to the installer label Apr 10, 2021
@chenghlee chenghlee added this to the Release TBD milestone Apr 10, 2021
@aoliong
Copy link

aoliong commented Jul 22, 2021

Hi, when I fixed the Installer, and change the md5 in Installer, then I got this:

[/project/miniconda3] >>> 
PREFIX=/project/miniconda3
Unpacking payload ...
./Miniconda3-py39_4.9.2-Linux-x86_64.sh: line 412: /project/miniconda3/conda.exe: cannot execute binary file: Exec format error
./Miniconda3-py39_4.9.2-Linux-x86_64.sh: line 414: /project/miniconda3/conda.exe: cannot execute binary file: Exec format error`

How can I fix this ?


I found the solution. The Installer does not need to be modified. Just use this

source activate

@samuel-hunter
Copy link
Author

Hi @aoliong, it looks like the errors are within lines 412-414. Can you show me a snippet that has those line numbers?

@kenodegard kenodegard removed this from the Release TBD milestone Dec 3, 2021
@conda-bot conda-bot added the backlog issue has been triaged but has not been earmarked for any upcoming release label Dec 3, 2021
@jezdez
Copy link
Member

jezdez commented Dec 16, 2021

This seems to be an issue in the constructor version that Anaconda uses to build miniconda, which was already fixed in the main repo in https://github.com/conda/constructor/blob/a7ad3d2807129b2cdc596337b5081df1967002d5/constructor/header.sh#L591-L594

@jezdez
Copy link
Member

jezdez commented Dec 16, 2021

I've opened an internal ticket to track the fix.

@jezdez jezdez added the severity::2 critical; broken functionality with an unacceptably complex workaround label Dec 16, 2021
@stmlange
Copy link

stmlange commented Dec 23, 2022

Any updates on this? This still seems to be a problem with the latest installer:

$ curl -sSL https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
$ sha256sum *
00938c3534750a0e4069499baf8f4e6dc1c2e471c86a59caa0dd03f4a9269db6  Miniconda3-latest-Linux-x86_64.sh
$ chmod +x Miniconda3-latest-Linux-x86_64.sh
$ ./Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda3

fails with

./Miniconda3-latest-Linux-x86_64.sh: 438: [[: not found
./Miniconda3-latest-Linux-x86_64.sh: 444: [[: not found

Thanks!

@AnkushMalaker
Copy link

AnkushMalaker commented Dec 23, 2022

I'm facing the same issue with the py39 installer as-well.
I get the following logs:

PREFIX=/home/ubuntu/miniconda3
Unpacking payload ...
                                                                                                         
Installing base environment...


Downloading and Extracting Packages


Downloading and Extracting Packages

Preparing transaction: done
Executing transaction: done
Miniconda3-latest-Linux-x86_64.sh: 438: [[: not found

Installing * environment...

Miniconda3-latest-Linux-x86_64.sh: 444: [[: not found

CondaFileIOError: '/home/ubuntu/miniconda3/pkgs/envs/*/env.txt'. [Errno 2] No such file or directory: '/home/ubuntu/miniconda3/pkgs/envs/*/env.txt'

This is a fresh install of ubuntu 22.10.

Edit: This issue for me was caused because I was using sh to execute the installer instead of bash.
Using bash Miniconda3-latest-Linux-x86_64.sh to install worked.
@stmlange Could you try the same?

@stmlange
Copy link

Thanks for the hint! I was initially trying the source activate which was suggested in one of the previous comments which didn't work. Using bash Miniconda3-latest-Linux-x86_64.sh to install works fine on ubuntu jammy (22.04.1 LTS).

@jonhermansen
Copy link

I ran into this issue today as well, thank you all for the suggestion of running under bash

Perhaps the shebang at the top of the script, should be changed?

@dbast
Copy link
Member

dbast commented Dec 23, 2022

related conda/constructor#596

@ezyang
Copy link

ezyang commented Dec 24, 2022

This is more pressing now that focal is shipping a sh that doesn't understand this bash-ism

ezyang added a commit to pytorch/pytorch that referenced this issue Dec 24, 2022
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
ezyang added a commit to pytorch/pytorch that referenced this issue Dec 24, 2022
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyangfb.com>

ghstack-source-id: 38cc3d169355f973974fac918ba6c18808454227
Pull Request resolved: #91371
@pat-s
Copy link

pat-s commented Dec 25, 2022

I also just hit this in focal latest. Quite unfortunate from an outside perspective.

Invoking the .sh script with ./ should really work as one rarely calls bash <script>.sh in an automation workflow. A working shebang definition should solve this.

pytorchmergebot pushed a commit to pytorch/pytorch that referenced this issue Dec 26, 2022
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: #91371
Approved by: https://github.com/albanD
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this issue Dec 28, 2022
…rict POSIX sh"

See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyangfb.com>

[ghstack-poisoned]
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this issue Dec 28, 2022
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyangfb.com>

[ghstack-poisoned]
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this issue Dec 28, 2022
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyangfb.com>

ghstack-source-id: 9a39ea1c200e633cc96a1cd12867cc4d835e4b97
Pull Request resolved: #91371
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this issue Dec 28, 2022
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: #91371
Approved by: https://github.com/albanD
@stmlange
Copy link

Thanks for your quick reaction and fix despite the fact that I have re-used an old issue in the wrong repo (for me it wasn't clear where to report it and this one was still open) :-)

@sbrozell
Copy link

Thanks. When will the fix go live ?

pruthvistony pushed a commit to ROCm/pytorch that referenced this issue Jan 3, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
pruthvistony pushed a commit to ROCm/pytorch that referenced this issue Jan 3, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
pruthvistony pushed a commit to ROCm/pytorch that referenced this issue Jan 3, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
pruthvistony pushed a commit to ROCm/pytorch that referenced this issue Jan 3, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
pruthvistony pushed a commit to ROCm/pytorch that referenced this issue Jan 3, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
pruthvistony pushed a commit to ROCm/pytorch that referenced this issue Jan 3, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
pruthvistony pushed a commit to ROCm/pytorch that referenced this issue Jan 3, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
@sbrozell
Copy link

sbrozell commented Jan 4, 2023

Is it expected that this will ultimately be fixed in release distribution ?

mithro added a commit to mithro/skywater-pdk that referenced this issue Jan 7, 2023
Fixes the issue caused by conda/conda#10431 by
including mithro/make-env#31

Signed-off-by: Tim 'mithro' Ansell <tansell@google.com>
jithunnair-amd pushed a commit to ROCm/pytorch that referenced this issue Jan 10, 2023
See also conda/conda#10431

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: pytorch#91371
Approved by: https://github.com/albanD
gmarkall added a commit to gmarkall/llvmlite that referenced this issue Jan 16, 2023
The Minconda installer seems to expect that `[[` can be used in all sh
implementations, which is not necessarily the case (there are some
discussions around this issue e.g. in
conda/conda#10431).

To attempt to work around this, we run the installer with bash instead.
@donaldafeith
Copy link

Remember to restart. (I'm running WSL 2 and was able to install it by)

  • curl -sSL https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
  • chmod +x Miniconda3-latest-Linux-x86_64.sh
  • ./Miniconda3-latest-Linux-x86_64.sh -b -p /home/user/miniconda3a **because I have windows python installed with miniconda /user/miniconda3
  • conda config --set auto_activate_base false
  • exited out of WSL2
  • Restarted WSL2
  • conda --version

@divinity76
Copy link

seems to still be unfixed as of 2023-01-20, and the bash -c workaround does NOT work, i can reproduce it with this Dockerfile:

FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive 
RUN apt-get update -y
RUN apt-get install -y wget
RUN wget --no-verbose 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh';
RUN chmod +x ./Miniconda3-latest-Linux-x86_64.sh;
RUN bash -c './Miniconda3-latest-Linux-x86_64.sh -b -p /miniconda;'

yields

$ docker build -f Dockerfile .;
Sending build context to Docker daemon  92.34MB
Step 1/28 : FROM ubuntu:22.04
 ---> 6b7dfa7e8fdb
Step 2/28 : ENV DEBIAN_FRONTEND=noninteractive
 ---> Using cache
 ---> 9fcfd668e8a3
Step 3/28 : RUN apt-get update -y
 ---> Using cache
 ---> 76449545c502
Step 4/28 : RUN apt-get install -y wget
 ---> Using cache
 ---> 5c0ab313726e
Step 5/28 : RUN wget --no-verbose 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh';
 ---> Running in 763122d8236d
2023-01-20 02:29:04 URL:https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh [72402405/72402405] -> "Miniconda3-latest-Linux-x86_64.sh" [1]
Removing intermediate container 763122d8236d
 ---> aa1dcca06d6f
Step 6/28 : RUN chmod +x ./Miniconda3-latest-Linux-x86_64.sh;
 ---> Running in 06dec8f155ac
Removing intermediate container 06dec8f155ac
 ---> 333dd872b5e3
Step 7/28 : RUN bash -c './Miniconda3-latest-Linux-x86_64.sh -b -p /miniconda;'
 ---> Running in 85b760c4cf22
PREFIX=/miniconda
Unpacking payload ...
                                                                                                               
Installing base environment...


Downloading and Extracting Packages


Downloading and Extracting Packages

Preparing transaction: ...working... done
Executing transaction: ...working... done
./Miniconda3-latest-Linux-x86_64.sh: 438: [[: not found

Installing * environment...

./Miniconda3-latest-Linux-x86_64.sh: 444: [[: not found

CondaFileIOError: '/miniconda/pkgs/envs/*/env.txt'. [Errno 2] No such file or directory: '/miniconda/pkgs/envs/*/env.txt'

The command '/bin/sh -c bash -c './Miniconda3-latest-Linux-x86_64.sh -b -p /miniconda;'' returned a non-zero code: 1

@dbast
Copy link
Member

dbast commented Jan 20, 2023

you have to call bash Miniconda3-latest-Linux-x86_64.sh ... without -c ... and also no need for the chmod call!

@divinity76
Copy link

@dbast that actually worked! thanks! btw i'm positive there is a bug in the current Miniconda3-latest-Linux-x86_64.sh where it uses #!/bin/bash-exclusive syntax with the shebang #!/bin/sh , causing normal invocation to crash, but when the file is invoked with bash Miniconda...sh , the shebang will be ignored, and it will be parsed with bash-rules regardless of shebang~

@Aemon-Algiz
Copy link

@divinity76 You are a hero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog issue has been triaged but has not been earmarked for any upcoming release severity::2 critical; broken functionality with an unacceptably complex workaround source::community catch-all for issues filed by community members type::installer indicates a request or issue pertaining to the installer
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.