Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between $HOME and '~' (tilde)?

Tags:

linux

bash

centos

I had always thought that $HOME and ~ were exactly the same and thus could be used interchangeably. Today, when I tried to install pylibmc, a python binding to memcached, on my shared server the use of ~ gave me error but not $HOME. I would like to reason out why.

libmemcached is a requirement for pylibmc. I have libmemcached installed under my home directory because I have no root on the server. As a result, to install pylibmc, I need to make sure the installation script knows where to find libmemcached.

When executing python setup.py install --with-libmemcached=~, the installation script runs

 gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall \   -Wstrict-prototypes -fPIC -DUSE_ZLIB -I~/include \   -I/usr/local/include/python2.7 -c _pylibmcmodule.c \   -o build/temp.linux-i686-2.7/_pylibmcmodule.o -fno-strict-aliasing 

which gives the errors that libmemcached can't be found.

If I change to --with-libmemcached=$HOME, the script runs

 gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall \   -Wstrict-prototypes -fPIC -DUSE_ZLIB -I/home/waterbotte/include \   -I/usr/local/include/python2.7 -c _pylibmcmodule.c \   -o build/temp.linux-i686-2.7/_pylibmcmodule.o -fno-strict-aliasing 

without any problem. It looks like the problem is that tilde doesn't get resolved. But why?

like image 912
tamakisquare Avatar asked Jul 20 '12 21:07

tamakisquare


People also ask

What does cd tilde mean?

cd tilde. To go home. From the Unix C-shell and Korn-shell command cd ~, which takes one to one's $HOME (cd with no arguments happens to do the same thing). By extension, may be used with other arguments; thus, over an electronic chat link, cd ~coffee would mean “I'm going to the coffee machine.”

What does the tilde symbol represent in Linux?

The tilde (~) is a Linux "shortcut" to denote a user's home directory. Thus tilde slash (~/) is the beginning of a path to a file or directory below the user's home directory. For example, for user01, file /home/user01/test. file can also be denoted by ~/test.

Why is tilde home?

This practice derives from the Lear-Siegler ADM-3A terminal in common use during the 1970s, which happened to have the tilde symbol and the word "Home" (for moving the cursor to the upper left) on the same key. You can find photos of the Lear-Siegler ADM-3A keyboard on this site.


2 Answers

The tilde is part of a shell expansion (like in bash, csh, zsh, etc). The $HOME variable is exportable and can be used independent of a specific shell.

like image 193
Jon Lin Avatar answered Oct 21 '22 13:10

Jon Lin


The shell replaces ~ with the user's home directory (update: or perhaps by the home directory of some other user, if ~ is followed by something other than a /), but only if it's the first character of a word.

--with-libmemcached=~ has ~ not in the beginning, so the shell leaves it alone.

like image 30
n. 1.8e9-where's-my-share m. Avatar answered Oct 21 '22 14:10

n. 1.8e9-where's-my-share m.