Program name ($0) relative paths should not be expanded
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 79
Description
Describe the bug
sh and sh-like shells don't expand relative paths when executing a program or script, but nushell does. This behaviour in nushell break assumes by some scripts, causing them to fail.
To demonstrate, if I create a script to print the program name it was called with:
$ echo "#!/bin/sh\necho $0" o> test.sh
$ chmod +x test.sh
Then if I execute it via a relative path in the current directory, the results are different between nushell and sh:
~/tmp $ cat test.sh
#!/bin/sh
echo $0
~/tmp $ ./test.sh
/home/user/tmp/./test.sh
~/tmp $ sh -c './test.sh'
./test.sh
How to reproduce
- create an executable file that will print the name of the program being executed (eg.
$0in bash, or$PROGRAM_NAMEin ruby):
$ echo "#!/bin/sh\necho $0" o> test.sh
$ chmod +x test.sh
- execute the file from nushell using a relative path, and note that the path is expanded.
$ ./test.sh
/home/user/tmp/./test.sh
Expected behavior
The path should not be expanded. It should remain as given by the user, to be consistent with other shells, and not break assumptions that scripts have.
Configuration
NA - same results with nu -n
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior described with an executable script run through nushell, comparing its program name with sh -c './test.sh'. Trace the relative-path execution entry point and add coverage showing that the user-supplied relative path is preserved; done means ./test.sh is reported as ./test.sh rather than an expanded absolute path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100