镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

failing to source virtualenvwrapper on alpine linux (ash) #105

Description

@agowa

Hi, currently the virtualenvwrapper.sh script fails to be sourced on alpine linux.

This line of code

export VIRTUALENVWRAPPER_SCRIPT="${.sh.file}"

currently causes -ash: /usr/bin/virtualenvwrapper.sh: line 109: syntax error: bad substitution when using the ash shell on alpine linux.

Activity

  1. agowa commented on Sep 2, 2024

    @agowa
    Author

    May be the same issue as with fish shell however I've not tried it there. Just guessing from the surrounding code.
    #100

  2. ferdnyc commented on Mar 24, 2025

    @ferdnyc
    Contributor

    ${.sh.file} is ksh syntax, but ksh support was dropped in commit d736549 so that branch probably should've been taken out too.

    That still won't help your shell, though, because without a default VIRTUALENVWRAPPER_SCRIPT won't get set.

    Really, using $0 should probably be the default -- that will even work in Bash, under most cases, although $BASH_SOURCE is certainly better if it's available.

  3. ferdnyc commented on Mar 24, 2025

    @ferdnyc
    Contributor

    Although, interestingly, when sourcing a script it seems that $0 is the ONLY thing that works for Zsh, and $BASH_SOURCE is the only thing that works for Bash.

    so I guess the first question is, if you save this script to a file test_arg0.sh:

    echo "0: $0"
    echo "BASH_SOURCE: ${BASH_SOURCE}"
    echo "ZSH_ARGZERO: ${ZSH_ARGZERO}"
    echo "ZSH_SCRIPT: ${ZSH_SCRIPT}"
    
    # Feel free to add any additional variables
    # your shell's documentation indicates might be useful.

    Then what do you get in ash for each of these scenarios?

    1. (At any shell prompt):
      ash test_arg0.sh
    2. (At an ash shell prompt):
      source test_arg0.sh

    Here's what I get

    Zsh

    $ zsh test_arg0.sh
    0: test_arg0.sh
    BASH_SOURCE: 
    ZSH_ARGZERO: test_arg0.sh
    ZSH_SCRIPT: test_arg0.sh
    
    $ source test_arg0.sh
    0: test_arg0.sh
    BASH_SOURCE: 
    ZSH_ARGZERO: zsh
    ZSH_SCRIPT: 

    Bash

    $ bash test_arg0.sh 
    0: test_arg0.sh
    BASH_SOURCE: test_arg0.sh
    ZSH_ARGZERO: 
    ZSH_SCRIPT: 
    
    $ source test_arg0.sh 
    0: bash
    BASH_SOURCE: test_arg0.sh
    ZSH_ARGZERO: 
    ZSH_SCRIPT: 
  4. added a commit that references this issue on Mar 24, 2025
    5840f04
  5. ferdnyc commented on Mar 24, 2025

    @ferdnyc
    Contributor

    May be the same issue as with fish shell however I've not tried it there. Just guessing from the surrounding code.
    #100

    I don't think fish is ever gonna work. It dumps out with an error anytime a variable reference uses curly braces! (What are they THINKING??)

    $  source test_arg0.sh
    test_arg0.sh (line 2): Variables cannot be bracketed. In fish, please use "$BASH_SOURCE".
    echo "BASH_SOURCE: ${BASH_SOURCE}"
  6. dhellmann commented on Mar 29, 2025

    @dhellmann
    Contributor

    I think there's an alternative implementation for fish.

    I've never heard of the ash shell. If its syntax can be supported without breaking anything, I could review patches.

  7. ferdnyc commented on Mar 30, 2025

    @ferdnyc
    Contributor

    @DHELLMAN See #117, though I don't know whether that's a complete solution. It at least gives ash and others like it a fighting chance, by no longer defaulting to KSH syntax for all shells that aren't Bash or Zsh.

  8. added a commit that references this issue on Mar 31, 2025
    e9efe7e
  9. added a commit that references this issue on Mar 31, 2025
    23c86d9
  10. ferdnyc commented on Mar 31, 2025

    @ferdnyc
    Contributor

    I just remembered that alpine publishes docker containers, which makes it really easy to test the ash shell on a different system. So...

    $ docker pull alpine:latest
    $ docker run -t -i alpine:latest /bin/ash
    / # cat > test_arg0.sh
    echo "0: $0"
    echo "BASH_SOURCE: ${BASH_SOURCE}"
    echo "ZSH_ARGZERO: ${ZSH_ARGZERO}"
    echo "ZSH_SCRIPT: ${ZSH_SCRIPT}"
    / # source test_arg0.sh
    0: /bin/ash
    BASH_SOURCE: 
    ZSH_ARGZERO: 
    ZSH_SCRIPT: 

    Conclusion: None of the existing methods will work for Ash. $0 shows us the wrong path. So we need to look for other supported options.

    Looking at the man page, I don't see any documented method of determining the path where a sourced script is located. $0 is all it supports, and that remains the path to the shell binary.

  11. ferdnyc commented on Mar 31, 2025

    @ferdnyc
    Contributor

    Ah, crap, that's my fault, I shouldn't have marked that PR as "fixes" this issue, since it doesn't.

    ...Thanks, you beat me to it.

  12. ferdnyc commented on Mar 31, 2025

    @ferdnyc
    Contributor

    I've posted a StackExchange question asking how this might be solved.

    (Very belated update: StackExchange produced nothing other than additional confirmation that it doesn't seem to be possible.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions