sixtyfootersdude
sixtyfootersdude

Reputation: 27231

Bourne Shell: Convert ~/Desktop to /users/me/Desktop

The keytool does not resolve impartial directories. Ie this works:

keytool -keystore "/users/me/Desktop" ...

This doesn't:

keytool -keystore "~/Desktop" ...

Is there something that I could call like this:

keytool -keystore "$(<cmd> ~/Desktop)" ...

Update

I guess I should actually be more specific:

This is really what I am doing:

myVar=~/Desktop
<allow user to overwrite default value of myVar>
keytool -keystore "$myVar" ...

I don't think that it is safe to have $myVar unquoted in the keytool command in case someone puts some malicious code in there.

Upvotes: 0

Views: 176

Answers (4)

mihi
mihi

Reputation: 6735

How about

keytool -keystore "$(echo ~/Desktop)"

or

keytool -keystore "$HOME/Desktop"

But, on the other hand, ~/Desktop should work fine as well. Tried with bash only, don't have any other Bourne shells here.

Upvotes: 0

frankc
frankc

Reputation: 11473

eval echo "~/foo"

e.g. keytool -keystore $(eval echo ~/Desktop)

Upvotes: 1

Will Hartung
Will Hartung

Reputation: 118671

That's because you are quoting the path. Keytool, or any other command line program in unix is agnostic of the wildrcards, because the shell is used to actually expanding the path names. If you don't quote the path, it'll work peachy.

Upvotes: 4

Gabe
Gabe

Reputation: 86718

I don't think this is a programming question, but did you try it without the quotes? i.e.

keytool -keystore ~/Desktop ...

Upvotes: 2

Related Questions