Skip to content

Expansion of $0 changed in 3.5.0 release even for bash scripts #9143

@vlitvin

Description

@vlitvin

Expansion of $0 differs from one in bash and zsh in script, even when shell explicitly set with shebang. My test show that this behaviour changed in 3.5.0 resulting in broken bash scripts.

Fish version:

  fish --version
  fish, version 3.5.1

System version:

$ uname -a
Darwin XXXXX-MacBook-Pro.local 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64
$ echo $TERM
xterm-256color

I've tried sh -c 'env HOME=$(mktemp -d) fish' and got same results

Steps to reproduce:

# Create simple bash script
echo <<EOF > ./expansion.sh
#!/usr/bin/env bash

echo $0
EOF

# Make it executable
chmod +x ./expansion.sh

# Observe different output
./expansion.sh
<absolute_path>/expansion.sh

bash ./expansion.sh
./expansion.sh

zsh ./expansion.sh
./expansion.sh

I know that compatability with other shells not guaranteed, but it would be nice to have at least clear statement about it in changelog.
Though, it's not crystal clear to me, why behaviour differs even with shebang.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions