A common practice in shell configuration files like `.bashrc` or `.zshrc` is to add directories to the `PATH` environment variable. When using a tilde (`~`) to represent the home directory within a quoted string, for example `export PATH="$PATH:~/.local/bin/"`, the shell does not perform tilde expansion. This means `~` is treated as a literal character, resulting in a path like `./~/.local/bin/` being added to `PATH` instead of the intended `/home/<user>/.local/bin/`.
Bash documentation specifies that tilde expansion occurs only in unquoted inputs. While Bash and Zsh do perform tilde expansion in unquoted variable assignments (e.g., `export PATH=$PATH:~/.local/bin`), relying on this is fragile due to potential issues with whitespace. The problem was identified when a sandboxing tool, `nono agent`, warned about `PATH` entries it could write to, specifically flagging `~/.local/bin/`.
A practical example shows that if `PATH` is set to `"~/.local/bin/"`, and a directory `./~/.local/bin/` is created containing an executable named `kek`, the shell successfully finds and runs `kek` from this literal `~` directory. This confirms that the home directory was not involved in the path resolution, and a new directory structure was implicitly created.
To correctly add a home-relative path to `PATH` within a quoted string, users should explicitly use the `$HOME` environment variable. The correct syntax is `export PATH="$PATH:$HOME/.local/bin/"`. This ensures that the home directory path is properly expanded before being added to `PATH`.
Users can check their current `PATH` for this issue by running `echo "$PATH" | grep '~'` or `echo "$PATH" | tr ':' '\n' | grep '~'`. If any output contains `~`, it indicates a potential misconfiguration that should be corrected in `.bashrc`, `.zshrc`, or `.profile` files by replacing `~` with `$HOME`.
✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →
One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.
One email a day. Unsubscribe in one click, any time.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
When defining the PATH environment variable in shell configuration files, using a tilde (~) within double quotes, such as `export PATH="$PATH:~/.local/bin/"`, prevents the tilde from expanding to the user's home directory. Instead, the shell interprets `~` literally, creating a relative path like `./~/.local/bin/` rather than `/home/<user>/.local/bin/`. This behavior can lead to unexpected directory structures and executable lookup issues.