Yes, absolutely. The same holds true for Bash.
Bash is a POSIX-compliant shell, and both tilde expansion (~) and variable expansion ($HOME) are fundamental, standardized features that work identically in this regard across compliant shells like Bash, Zsh, Ksh, etc.
Here's why:
$HOME Environment Variable: Like Fish, Bash relies on the $HOME environment variable being correctly set by the operating system during the login or shell startup process. This variable points to the user's home directory.
- Tilde Expansion (
~): Bash performs tilde expansion before executing most commands. When Bash encounters ~ at the beginning of a word (or in specific contexts), it replaces it with the value of the $HOME environment variable. So, ~/some/path becomes /home/username/some/path.
- Variable Expansion (
$HOME): Bash also performs standard variable expansion. When it sees $HOME, it substitutes the value of that environment variable. So, $HOME/some/path also becomes /home/username/some/path.
Equivalence and Robustness:
- Mechanism: The underlying mechanism is the same: both rely on
$HOME. Tilde expansion is just syntactic sugar that Bash (and others) translates into using $HOME.
- Reliability: Unless the
$HOME environment variable itself is unset or corrupted (which is exceedingly rare in normal operation), both ~/ and $HOME/ will reliably resolve to your home directory in Bash initialization files (like .bashrc, .bash_profile, .profile).
"More Standard" Aspect:
You mentioned Bash being "more standard." While "standard" can be interpreted in various ways (POSIX vs. market share), Bash is indeed the default shell on many Linux distributions and macOS, making it the de facto standard for many users. However, for features like ~ and $HOME expansion, Fish is also compliant and implements these standard behaviors correctly. The core mechanism isn't unique to Bash; it's common to POSIX shells.
Conclusion:
In Bash initialization scripts, ~/ and $HOME/ are equally robust and reliable ways to refer to your home directory. Choose whichever syntax you prefer for readability. The context of where the shell starts (its current working directory) still matters for other relative paths, but not for paths explicitly anchored to the home directory using ~ or $HOME.