Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

home directory expansion (~) within an argument

When I enter the following (BASH):

rdesktop -r disk:bacon=~/bacon host

It does not expand to

rdesktop -r disk:bacon=/home/me/bacon host

It seems the "disk:" part is the problem as can be seen in:

$ echo bacon=~/bacon disk:bacon=~/bacon

bacon=/home/me/bacon disk:bacon=~/bacon

How can I make tilde expand?

like image 956
Yoo Avatar asked Nov 06 '09 07:11

Yoo


People also ask

Which character expands to the current user's home directory?

An unquoted tilde character (~) at the beginning of a word is expanded according to the following rules: ~ expands to the value of the HOME variable (the current user's home directory).

How do I know if an argument is a directory?

First check the provides argument is the directory or not using the if statement using the -d option for the first argument using the $1 parameter. If it is true then print the message that the provided argument is the directory. If the argument is not the directory then check it for the file.

What command will take you to your home directory?

Use the cd command to move to your home directory, and try the ls -l command.

What is home directory in shell?

The Linux home directory is a directory for a particular user of the system and consists of individual files. It is also referred to as the login directory. This is the first place that occurs after logging into a Linux system. It is automatically created as "/home" for each user in the directory'.


2 Answers

While ~ does not expand (it's used as specially routed of the path), $HOME does.

rdesktop -r disk:bacon=$HOME/bacon host

But be careful with environment-changing su!

like image 138
P Shved Avatar answered Oct 26 '22 07:10

P Shved


rdesktop -r disk:bacon=$(echo ~/bacon) host

will do it. It won't please the eye, but it will work.

like image 28
pilcrow Avatar answered Oct 26 '22 06:10

pilcrow