On Wed, Dec 18, 2019 at 09:42:21PM -0500, rhkra...@gmail.com wrote: > Thanks to all who replied! > > This script (or elements of it) looks useful to me, but I don't fully > understand it -- I plan to work my way through it -- I have a few questions > now, I'm sure I will have more after I get past the first 3 (or more > encouraging to me, first 6) lines. > > Questions below: > > On Wednesday, December 18, 2019 12:26:04 PM to...@tuxteam.de wrote: > > On Wed, Dec 18, 2019 at 12:02:56PM -0500, rhkra...@gmail.com wrote: > > > #!/bin/bash > > home=${HOME:-~} > > What does that line do, or more specifically, what does the :-~ do -- note > the > following:
The "-" doesn't belong to the "~" but to the ":" ;-) The construction is (see the section "Parameter Expansion" in the bash manual): ${parameter:-word} Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. ("parameter" is the bash manual's jargon for what we colloquially call "shell variable"). So this means: "if HOME is set, then use that. Otherwise use whatever tilde ('~') expands to". This is my way to find a home, but to allow the script's user to override it by setting HOME to some other value. > rhk@s19:/rhk/git_test$ echo ${HOME:-~} > /home/rhk > rhk@s19:/rhk/git_test$ echo ${HOME} > /home/rhk > > > if test -z "$home" -o \! -d "$home" ; then > > What does the -o \! do -- hmm, I guess \! is a bash "refeence" to the owner > -- > I guess I should look for it in man bash... No, this exclamation mark ain't for bash -- it's an argument to "test" which it interprets as "not". Since the "!" can mean to bash something in some contexts, as you found out, I escaped it with the "\" [1]. So this "if" means: if ## if test ## -z "$home" ## the value of $home is empty -o ## or \! ## there is NOT -d "$home" ## a directory named "$home" ## we're homeless. > I'm sure I'll have more questions as I continue, but that is enough for me > for > tonight. Questions welcome! Cheers [1] Actually, on revisiting things, I would tend to write '!' instead of \! these days. -- tomás
signature.asc
Description: Digital signature