Chet Ramey wrote: > Angel Tsankov wrote: >> Hi, >> >> Using bash 3.2.48(1)-release, echo ""~root prints ~root instead of >> /root. Is this the expected behaviour? > > Yes. The tilde is not the first character in the word. Portions of > words to be tilde-expanded can't be quoted at all, either.
I see. I came to this example from a real-world problem and, in case someone can help, here it is. I'd like to append a path to CPATH (separating it from the current contents of CPATH with a colon only if CPATH is set and is not empty). The path-to-append points under usr1's home directory. Also this should work in contexts such as CPATH=... <some command>. I tried CPATH="${CPATH}${CPATH:+:}"~usr1/blah/blah. (I quote expansions just to be on the safe side, though I think home directories may not contain spaces.) Of course, this did not work for the reason pointed above. However, removing the quotes still does not make the tilde-expression to expand. How can I achieve my goal? Regards, Angel Tsankov