Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use $HOME over ~ (tilde) in a shell script?

Is there any reason to use the variable $HOME instead of a simple ~ (tilde) in a shell script?

like image 463
mybuddymichael Avatar asked May 08 '11 22:05

mybuddymichael


People also ask

What is $home in shell script?

$HOME is a Linux bash shell variable. It indicates the home directory of the current user; the default argument for the cd command. The value of this variable is also used when performing tilde expansion.

What is tilde in shell script?

~/ (tilde slash) 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.

Can I use tilde in Bash script?

Bash also performs tilde expansion on words satisfying the conditions of variable assignments (see Shell Parameters) when they appear as arguments to simple commands. Bash does not do this, except for the declaration commands listed above, when in POSIX mode.

What is role of $0 $? And $# in shell scripting?

If you execute ./script.sh , $0 will give output ./script.sh but if you execute it with bash script.sh it will give output script.sh . Show activity on this post. They are called the Positional Parameters.


1 Answers

Tilde expansion doesn't work in some situations, like in the middle of strings like /foo/bar:~/baz

like image 169
Random832 Avatar answered Sep 24 '22 16:09

Random832