[opensuse] resolving ~ on the command line ?
When I run: myexecutable --config=~/job00001.conf from the bash command line, surely am I right to expect ~/job00001.conf to be resolved to "/home/per/job00001.conf" ? -- Per Jessen, Zürich (15.4°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
* Per Jessen <per@computer.org> [05-18-18 15:51]:
When I run:
myexecutable --config=~/job00001.conf
from the bash command line, surely am I right to expect ~/job00001.conf to be resolved to "/home/per/job00001.conf" ?
"~" is a *shortcut* for $HOME, so whatever $HOME resolves to is what you will expect and should realize when using "~". -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Registered Linux User #207535 @ http://linuxcounter.net Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Hello, Am Freitag, 18. Mai 2018, 21:50:25 CEST schrieb Per Jessen:
When I run:
myexecutable --config=~/job00001.conf
from the bash command line, surely am I right to expect ~/job00001.conf to be resolved to "/home/per/job00001.conf" ?
~ gets expanded by the shell, but only if it's a separate "word" with spaces around. With --foo=~/whatever, it won't work: # echo --foo=~/public_html --foo=~/public_html # echo --foo ~/public_html # with space instead of = --foo /home/cb/public_html Using $HOME should always work ;-) Regards, Christian Boltz -- Linux - und dein PC macht nie wieder blau. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Christian Boltz wrote:
Hello,
Am Freitag, 18. Mai 2018, 21:50:25 CEST schrieb Per Jessen:
When I run:
myexecutable --config=~/job00001.conf
from the bash command line, surely am I right to expect ~/job00001.conf to be resolved to "/home/per/job00001.conf" ?
~ gets expanded by the shell, but only if it's a separate "word" with spaces around. With --foo=~/whatever, it won't work:
Thanks Christian, thanks David! -- Per Jessen, Zürich (14.1°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Christian & Per, et al -- ...and then Per Jessen said... % % Christian Boltz wrote: % % > ~ gets expanded by the shell, but only if it's a separate "word" with % > spaces around. With --foo=~/whatever, it won't work: Weeeellllll... Not exactly. To wit: davidtg@wench:~> echo $SHELL /bin/bash davidtg@wench:~> echo ~ /mnt/data/home/davidtg davidtg@wench:~> FOO=~ ; echo $FOO /mnt/data/home/davidtg davidtg@wench:~> BAR=~/bar ; echo $BAR /mnt/data/home/davidtg/bar It even can work in a parameter: davidtg@wench:~> cat /tmp/T #!/bin/sh echo $1 davidtg@wench:~> /tmp/T foo=~/whatever foo=/mnt/data/home/davidtg/whatever The trick is to have it look like a param instead of an argument: davidtg@wench:~> /tmp/T --foo=~/whatever --foo=~/whatever However, the code that gets the raw tilde could also of course expand it pretty simply, too. % % Thanks Christian, thanks David! Always a pleasure :-) HANW :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
David T-G wrote:
It even can work in a parameter:
davidtg@wench:~> cat /tmp/T #!/bin/sh echo $1 davidtg@wench:~> /tmp/T foo=~/whatever foo=/mnt/data/home/davidtg/whatever
The trick is to have it look like a param instead of an argument:
davidtg@wench:~> /tmp/T --foo=~/whatever --foo=~/whatever
Can you also explain the difference? To the shell, both variations are invocations of a script with some text parameters.
However, the code that gets the raw tilde could also of course expand it pretty simply, too.
Sure, but I see no need put put shell logic in my code :-) -- Per Jessen, Zürich (14.2°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Hello, On Fri, 18 May 2018, Per Jessen wrote:
When I run:
myexecutable --config=~/job00001.conf
from the bash command line, surely am I right to expect ~/job00001.conf to be resolved to "/home/per/job00001.conf" ?
==== man bash ==== DEFINITIONS [..] word A sequence of characters considered as a single unit by the shell. Also known as a token. [..] EXPANSION [..] Tilde Expansion If a word begins with an unquoted tilde character (`~'), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [..] If this login name is the null string, the tilde is replaced with the value of the shell parameter HOME. [.] ==== In your case, the word is the complete '--config=~/job00001.conf' and that does not begin with the tilde. IOW: use ${HOME} if you need it inside a "word" or inside (double) quotes. Exp: $ echo myexecutable --config=~/job00001.conf myexecutable --config=~/job00001.conf $ echo myexecutable --config ~/job00001.conf myexecutable --config /home/dh/job00001.conf $ echo myexecutable "--config ~/job00001.conf" myexecutable --config ~/job00001.conf $ echo myexecutable "--config ${HOME}/job00001.conf" myexecutable --config /home/dh/job00001.conf $ echo myexecutable --config=${HOME}/job00001.conf myexecutable --config=/home/dh/job00001.conf HTH, -dnh -- "Powered-up hardware and sweat do not mix." -- Simon Cozens -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (5)
-
Christian Boltz
-
David Haller
-
David T-G
-
Patrick Shanahan
-
Per Jessen