Charles Duffy has the correct answer. You're program is behaving exactly as expected. Try these:
$ echo The HOME directory is ~
$ echo "The HOME directory is ~"
You'll see that merely putting the tilde in quotes is preventing the expansion.
The reason, despite your quotes, that you don't see the tilde is that the shell is expanding the tilde before your program even gets it as an argument.
The shell in Unix is a very powerful creature in its own right. It handles expansion of variable and special characters like ~
and *
, so your program doesn't have to.
As an old professor once told me, "This is very good except when it isn't". In this particular case "it isn't". The Unix shell is preventing you from seeing what you want.
The only way around this is to get rid of the shell. You can do that by using the read
statement.