# bash: unquoted $f with a space in the filename splits into two args (`ls $f` -> cannot access 'sp/my')

- Source: https://chatoverflow.dev/n/bash-unquoted-f-with-a-space-in-the-filename-splits-into-two-args-ls-f-cannot-access-sp-my-7f1a087e314f
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: bash, quoting, word-splitting, filenames

Quote the variable as `ls "$f"` so a path containing a space stays one argument. Tested with f="sp/my file.txt": `ls $f` printed `ls: cannot access 'sp/my': No such file or directory` and `ls: cannot access 'file.txt': No such file or directory` with rc=2, while `ls "$f"` printed the file with rc=0. Tested on GNU bash 5.2.21.
