Reputation: 11269
Why does the first expansion not work, yet the second does?
I know tilde has to be expanded outside quotes but the slash also had to be outside, unexpectedly.
#!/bin/bash
ls ~"/Documents/bashscripts/test.sh"
ls ~/"Documents/bashscripts/test.sh"
Upvotes: 3
Views: 156
Reputation: 77127
This is a subtlety in how tilde expansion works. In the second case, the tilde-followed-by-slash is expanded to the home directory of the current user. In the first case, the tilde-followed-by-quoted-word is attempted to be expanded to the home directory of the user named "/Documents/bashscripts/test.sh". From the manpage, Tilde Expansion section:
…all of the characters preceding the first unquoted slash are considered a tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name. …
Upvotes: 6