Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] "How to"



On Sat, May 17, 2014 at 2:11 PM, Stephen J. Turnbull <stephen@example.com> wrote:
>  > $ echo foo^Mecho bar
>  > echo bar
>  > $ echo foo; echo bar
>  > foo
>  > bar
>
> No, I was talking about in the context of a code block (such as a loop
> or a function body).  I think it looks better than a long line broken
> by colons.  I don't see when it would be useful for standalone
> commands.

I am not sure in a loop either... ^M does not help.

>  > > Splitting lines with \ <RET> is also occasionally
>  > > useful (but I forget how it interacts with things like strings).
>  >
>  > Easy: It just escapes nest character special meaning:
>  > $ echo foo\
>  > > bar
>  > foobar
>
> That's not a string.  I'm talking about the things bounded by pairs of
> " or '.

If the string is inside ', the \ will loose its meaning. Inside ",
this is less clear,
and I prefer generally to avoid it  (just afraid, I am a coward :-)
br@lorien:/export/home/br$ a=b
br@lorien:/export/home/br$ echo "c$a"
cb
br@lorien:/export/home/br$ echo "c\$a"
c$a
br@lorien:/export/home/br$ echo "c\
> $a"
cb
br@lorien:/export/home/br$ echo "c
> $a"
c
b

But I use a lot of "\" in my code (beside strings), for instance for
long command lines
that I want to read mode easily. For example:
       rsync \
            -aHixv \
            "${FILTER}" \
            ${RSYNCOPTS} \
            ${COMPRESS} \
            --delete \
            --delete-during \
            --delete-excluded \
            --modify-window=1 \
            --partial \
            --link-dest="${ldest}" \
            . \
            "${DEST}/daily-00" || status=$?

I do it also for strings, but I will tend to use the << notation when
it becomes long; this
allows to use " and ' in the string.
But this is just a personal choice, "\" is of course perfect too...

br.

-- 
2 + 2 = 5, for very large values of 2.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links