TL;DR
Get backup power and energy gear delivered free with Prime
- Fast, free delivery on millions of items
- Prime Video, Amazon Music and more included
- Member-only deals all year
A report published by developer Disconnect3d on Oct. 2 says quoting a tilde in a PATH assignment can stop Bash and Zsh from expanding it to the home directory. The resulting entry may point to a literal `~` directory in the current location; using `$HOME` avoids that issue.
Developer Disconnect3d reported Oct. 2 that a common shell configuration, `PATH=”$PATH:~/.local/bin”`, can add a literal tilde path rather than the user’s home directory. The report, prompted by a warning from the nono agent sandboxing tool, says replacing `~` with `$HOME` avoids the ambiguity.
The issue concerns how shells process tilde expansion. Disconnect3d’s report says Bash expands a tilde in certain unquoted positions, including in variable assignments immediately after an equals sign or a colon. In the example `PATH=”$PATH:~/.local/bin”`, however, the tilde is inside quotes, so it is not expanded as intended. The PATH entry can remain `~/.local/bin/` rather than becoming a path such as `/home/user/.local/bin/`.
That difference can change where a command runs from. Disconnect3d demonstrated creating a program under a literal `./~/.local/bin/` directory, then setting PATH to `~/.local/bin/` and running the program by name. The shell found and executed the file there; the user’s home directory was not involved. The report does not say every quoted tilde in every shell configuration will produce a security incident, but it shows that the resulting PATH entry may point somewhere unexpected.
The recommended correction is `export PATH=”$PATH:$HOME/.local/bin/”`. The post says the unquoted form, `export PATH=$PATH:~/.local/bin`, works in Bash and Zsh because of their assignment-specific tilde expansion rules. Disconnect3d describes relying on that behavior as fragile, noting that whitespace can break the assignment. The report suggests checking for literal tildes with `echo “$PATH” | tr ‘:’ ‘\n’ | grep ‘~’`.
PATH Can Point Somewhere Unexpected
PATH tells a shell where to search when a user runs a command without giving its full location. If an entry intended to identify a personal executable directory instead contains a literal tilde, the shell may search a different directory relative to its current location. That can cause commands to be missed or, if a matching file exists there, run from an unintended location.
The report makes this a practical configuration check rather than a claim of a newly discovered exploit. People who maintain `~/.bashrc`, `~/.zshrc` or `.profile` can inspect PATH and replace a quoted tilde with `$HOME` where appropriate. The exact effect depends on the PATH value and the directories and files present when a command is run.
shell scripting PATH management tools
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
A Sandbox Warning Revealed the Quoting Issue
Disconnect3d says the problem came to attention while using nono, an agent sandboxing tool. It displayed a warning identifying `~/.local/bin/` as a PATH entry the sandbox could write to. The developer said the warning looked suspicious and investigated how the entry was being interpreted.
The report refers to Bash documentation describing when tilde expansion occurs: an unquoted tilde at the start of a word can be expanded, and Bash also checks variable assignments for unquoted tilde prefixes after `=` or `:`. The key distinction in the reported example is the quoting around the whole assignment value. The post also says unquoted assignment behavior is available in both Bash and Zsh, but recommends `$HOME` as the clearer option.
““export PATH=”$PATH:$HOME/.local/bin/”””
— Disconnect3d, describing the safer assignment
home directory environment variable setup
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Shell Behavior Depends on the Assignment
The report focuses on the specific quoted assignment and describes Bash and Zsh behavior; it does not establish that every shell handles all PATH assignments identically. Nor does it document how many users have the configuration, whether the warning affects other nono users, or whether anyone has exploited a misplaced PATH entry. The post’s demonstration shows the mechanism, not evidence of an attack or broader impact.
A PATH entry containing `~` is a reason to inspect the relevant configuration, but its consequences depend on how it was set and what files exist in the directory the shell searches. The report recommends checking shell startup files and the live PATH rather than assuming that every tilde-containing entry has the same cause.
Linux shell configuration utilities
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Check Startup Files and PATH
Users can print PATH one entry per line with `echo “$PATH” | tr ‘:’ ‘\n’` and look for entries containing a tilde. If an entry was intended to refer to the home directory, the report recommends editing the relevant startup file—such as `.bashrc`, `.zshrc` or `.profile`—to use `$HOME`, then starting a new shell or reloading the file and checking the resulting PATH.
Disconnect3d said they intended to submit a pull request to make nono’s warning more verbose. The report did not provide a status for that proposed change, so whether the warning will be revised remains unconfirmed.
command line PATH troubleshooting tools
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
Does `~` always expand to the home directory in PATH?
No. The report says tilde expansion depends on where the tilde appears and whether it is quoted. In the quoted assignment `PATH=”$PATH:~/.local/bin”`, it may remain literal.
What should I use instead of a quoted tilde?
Use `$HOME`, as in `export PATH=”$PATH:$HOME/.local/bin”`, to specify the home directory in this assignment.
How can I check whether PATH contains a tilde?
Run `echo “$PATH” | tr ‘:’ ‘\n’ | grep ‘~’` to display entries containing a tilde. A match should be checked against the shell configuration that set it.
Does the report show that this is an active security attack?
No. It demonstrates how a command can be found in a literal `./~/.local/bin/` directory when PATH is set that way. It does not report an attack or establish broader exploitation.
Source: hn
Fall Picks
fall essentials
As an affiliate, we earn on qualifying purchases.
