Skip to content

[BUG] An empty path operand is treated as the current directory (mv "$empty" ../x renames the cwd) #322

Closed

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main @ 9851f51)
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

main @ 9851f51 (--version prints 0.0.0)

Language Runtime Version

Rust 1.100.0

Operating System

Linux 6.18 (aarch64)

Installation Method

built from source

Steps to Reproduce

Each line is a separate strands-shell -c '...' run in an empty directory. e is set but empty, as when a script's variable was never filled in.

mkdir w; cd w; touch g; e=; mv "$e" ../x; echo "rc=$?"; cd ..; ls
mkdir d; touch d/f; e=; cp -r "$e" d2; echo "rc=$?"; ls
touch f; e=; ls "$e"; echo "rc=$?"; test -e "$e"; echo "rc=$?"; touch "$e"; echo "rc=$?"
touch f; e=; ln -s "$e" l; echo "rc=$?"; ls

Expected Behavior

Same as bash and coreutils: an empty path does not exist, so each command fails and changes nothing.

mv: cannot stat '': No such file or directory      rc=1, ls prints: w
cp: cannot stat '': No such file or directory      rc=1, ls prints: d
ls: cannot access '': No such file or directory    rc=2, then rc=1, then touch fails with rc=1
ln: failed to create symbolic link 'l' -> ''       rc=1, ls prints: f

Actual Behavior

The empty path is read as the current directory.

Command Result
mv "$e" ../x rc=0; the current directory w is renamed to x
cp -r "$e" d2 prints cp: no such file or directory: /d, rc=1, but d2 is created
ls "$e" lists the current directory, rc=0
test -e "$e" rc=0
touch "$e" rc=0, silent
ln -s "$e" l rc=0; creates l

Additional Context

Found while reviewing #320. It is not caused by that PR: the results above are from main @ 9851f51. Once #299 is fixed, a literal "" operand reaches commands too, so these will be hit more often (today touch "" reports missing file operand only because the argument is dropped).

I ran debug builds through -c only, against the default virtual filesystem.

Possible Solution

I did not trace the cause. vfs::normalize (src/vfs.rs:732) drops empty components, so a relative "" joined to the cwd normalises to the cwd itself; rejecting an empty path with "no such file or directory" before that join would match POSIX, where an empty pathname does not resolve.

Related Issues

#320, #299

Activity

  1. added
    bug
    on Nov 19, 2026
  2. strandly-the-agent commented on Nov 19, 2026

    @strandly-the-agent
    CollaboratorAuthor

    This is worse than the report says: rm -rf with an empty operand deletes directories at the root, not just in the current directory. I missed it because I did not test rm when filing.

    strands-shell -c 'mkdir -p /tmp/keep; touch /tmp/keep/file; mkdir -p proj/tmp; cd proj; e=; rm -rf "$e"; echo "rc=$?"; echo "/tmp: $(ls /tmp)"'

    On main @ c28e1fb this prints rm: /tmp: permission denied, rc=1, and /tmp is empty afterwards. bash leaves everything in place and returns 0.

    The cause is two steps. vfs::absolute (src/vfs.rs:747) joins "" to the cwd, so rm lists the current directory. remove_recursive then builds each child as format!("{}/{}", path, entry.name) (src/commands/rm.rs:46), which with an empty path is /<name>. Every entry in the cwd is removed from the root instead.

    Today this needs a variable that is set but empty. #320 makes a quoted unset variable an empty argument, as bash does, so after it merges rm -rf "$UNSET" hits this too (on main it reports missing operand). I'd fix this issue before merging #320.

  3. ikenyal commented on Nov 19, 2026

    @ikenyal
    Contributor

    I'd like to work on this. It blocks #320, and I'd keep the fix focused on how commands handle empty path arguments.

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

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions