On Sunday 13 March 2011 14:12:20 Dan McGhee wrote:
> On 03/13/2011 01:06 PM, Dan McGhee wrote:
> > On 03/12/2011 08:00 PM, Neal Murphy wrote:
> >> <snipping>
> >>
> >> OR use:
> >> [ -e "file_1" ]&& [ ! -e "file_2" ]&& {
> >>
> >> <commands>;
> >>
> >> }
> >> # equivalent: test -e "$file_1&& test ! -e file_2&& {
> >>
> >> OR even use:
> >> [ -e "file_1" -a ! -e "file_2" ]&& {
> >>
> >> <commands>;
> >>
> >> }
> >> # equivalent: test -e "file_1" -a ! -e "file_2"&& {
> >>
> >> <snipping>
> >
> > Thanks for the insight, Neal. I'm starting to "play" with the script. In
> > the above examples are you suggesting that I enclose the names of the
> > files in quotes? I can't find this syntax in my references. If you are
> > suggesting it, is it so that no expansion takes place?
>
> I just found in the fine print of an example. ABS Guide uses it to allow
> for spaces.
Generally, single- and double-quotes allow for spaces in strings and for null
(or empty) strings. Double-quotes allow $xxx shell variables to be expanded;
single-quotes prevent expansion. Learning to automatically quote strings leads
to long-term hair retention. I usually use quotes because they result in
clearer syntax than one gets when using "\" escaping.
var="two words"
if [ "$var" == "two words" ]; then ... fi
and
var=two\ words
if [ "$var" == two\ words ]; then ... fi
are equivalent; the quoted form is clearer and is often the only way to make
it work.
Also, I must amend my msg re: the explicit semi-colon I included following the
last command when using the '&& { <commands>; } syntax. I was mistaken. They
aren't necessary when the commands are on separate lines, as in:
... && {
command 1
command 2
}
but it won't hurt to have them there. Semi-colons are only needed to terminate
commands when they are on one line, as in:
... && { command 2; command 2; }
It is standard, consistent shell syntax.
I thought I tested it both ways before clicking send; clearly I didn't.
N
--
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page