zsh-users
 help / color / mirror / code / Atom feed
* Multiline Anonymous Literal Strings
@ 2006-09-28 17:51 Chris Johnson
  2006-09-28 17:57 ` Michael Hernandez
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chris Johnson @ 2006-09-28 17:51 UTC (permalink / raw)
  To: zsh-users

Hi.

Anyone know of a way to compose a long literal string without doing
something like this?

   myvar="this is a really long string so long that I need to break"
   myvar="$myvar up the assignment"

In C, contiguous quoted strings are implicitly joined at a compile time:

   printf("This is a really long literal strong that will extend "
          "beyond 80 characters.\n");

In Perl and other languages, concatenation operators like ., &, and +
are available.

One application of this problem's solution is assigning aliases when the
command is longer than my terminal window.  I'd rather not introduce a
variable to make my code look nice.  I would like to be able to clean up
the following:

   alias mycommand="prog long list of options so long that it will reach
beyond the edge of the screen"

-- 
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Multiline Anonymous Literal Strings
  2006-09-28 17:51 Multiline Anonymous Literal Strings Chris Johnson
@ 2006-09-28 17:57 ` Michael Hernandez
  2006-09-28 18:27   ` Chris Johnson
  2006-09-28 18:26 ` Frank Terbeck
  2006-09-29  4:52 ` Bart Schaefer
  2 siblings, 1 reply; 6+ messages in thread
From: Michael Hernandez @ 2006-09-28 17:57 UTC (permalink / raw)
  To: Chris Johnson; +Cc: zsh-users


On Sep 28, 2006, at 1:51 PM, Chris Johnson wrote:

> Hi.
>
> Anyone know of a way to compose a long literal string without doing
> something like this?
>
>    myvar="this is a really long string so long that I need to break"
>    myvar="$myvar up the assignment"
>
> In C, contiguous quoted strings are implicitly joined at a compile  
> time:
>
>    printf("This is a really long literal strong that will extend "
>           "beyond 80 characters.\n");
>
> In Perl and other languages, concatenation operators like ., &, and +
> are available.
>
> One application of this problem's

You can try:

foo="some text on this line \
more text here \
yet more here"

the \'s keep everything on one line, i.e. the newlines aren't part of  
the string.

Mike


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Multiline Anonymous Literal Strings
  2006-09-28 17:51 Multiline Anonymous Literal Strings Chris Johnson
  2006-09-28 17:57 ` Michael Hernandez
@ 2006-09-28 18:26 ` Frank Terbeck
  2006-09-29  4:52 ` Bart Schaefer
  2 siblings, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2006-09-28 18:26 UTC (permalink / raw)
  To: zsh-users

Chris Johnson <cjohnson@cs.utk.edu>:
> Anyone know of a way to compose a long literal string without doing
> something like this?
> 
>    myvar="this is a really long string so long that I need to break"
>    myvar="$myvar up the assignment"

[snip]
myvar="this is a really long string so long that I need to break "
myvar+="up the assignment."
print ${myvar}
[snap]

[...]
> One application of this problem's solution is assigning aliases when the
> command is longer than my terminal window.  I'd rather not introduce a
> variable to make my code look nice.  I would like to be able to clean up
> the following:
> 
>    alias mycommand="prog long list of options so long that it will reach
> beyond the edge of the screen"

[snip]
pa=(
  -l
  one
  two
  three
  four
  five
  six
)
alias p="print ${pa}"
[snap]

Regards, Frank


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Multiline Anonymous Literal Strings
  2006-09-28 17:57 ` Michael Hernandez
@ 2006-09-28 18:27   ` Chris Johnson
  0 siblings, 0 replies; 6+ messages in thread
From: Chris Johnson @ 2006-09-28 18:27 UTC (permalink / raw)
  To: zsh-users

Michael Hernandez sent me the following 0.7K:

> >Anyone know of a way to compose a long literal string without doing
> >something like this?
> >
> >   myvar="this is a really long string so long that I need to break"
> >   myvar="$myvar up the assignment"
> 
> You can try:
> 
> foo="some text on this line \
> more text here \
> yet more here"
> 
> the \'s keep everything on one line, i.e. the newlines aren't part of  
> the string.

I had disregarded that solution because one can't embed piecewise
comments.  Sorry, I failed to mention that.  In the mailing list
archives I just found a message about anonymous arrays and how they
aren't supported.  All parameter expansion requires a named parameter,
so I think I'm out of luck.

-- 
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Multiline Anonymous Literal Strings
  2006-09-28 17:51 Multiline Anonymous Literal Strings Chris Johnson
  2006-09-28 17:57 ` Michael Hernandez
  2006-09-28 18:26 ` Frank Terbeck
@ 2006-09-29  4:52 ` Bart Schaefer
  2006-10-02 12:42   ` Chris Johnson
  2 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2006-09-29  4:52 UTC (permalink / raw)
  To: zsh-users

On Sep 28,  1:51pm, Chris Johnson wrote:
}
} Anyone know of a way to compose a long literal string without doing
} something like this?

The following requires "setopt multios" (which is the default, but a
few people turn it off):

alias mycommand=${(j: :)"${(f)$(<<<'print this is one string'
# This is a comment, but you cannot use unbalanced quotes in it
<<<'this is a more "     " spacey "     " string'
<<<'this is a third string')}"}

I believe it to be a parsing bug that the comment is not treated as
a comment until the command substution is executed, rather than when
it is "compiled", but it's the closest approximation to what you want
that you're going to find.

} In C, contiguous quoted strings are implicitly joined at a compile time

You darned young whippersnappers and your fancy-ANSI programming!  In
my day you ate your backslashes with your K&R, and liked them.
 
} In Perl and other languages, concatenation operators like ., &, and +
} are available.

And your point is?

The syntax of the shell language (which is only implemented by zsh, not
defined by it) precludes the use of infix operators.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Multiline Anonymous Literal Strings
  2006-09-29  4:52 ` Bart Schaefer
@ 2006-10-02 12:42   ` Chris Johnson
  0 siblings, 0 replies; 6+ messages in thread
From: Chris Johnson @ 2006-10-02 12:42 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer sent me the following 1.1K:

> } Anyone know of a way to compose a long literal string without doing
> } something like this?
> 
> The following requires "setopt multios" (which is the default, but a
> few people turn it off):
> 
> alias mycommand=${(j: :)"${(f)$(<<<'print this is one string'
> # This is a comment, but you cannot use unbalanced quotes in it
> <<<'this is a more "     " spacey "     " string'
> <<<'this is a third string')}"}

Thanks.  I was trying to develop something like this with the (j::), but
didn't know how to get the anonymous array.

> } In Perl and other languages, concatenation operators like ., &, and +
> } are available.
> 
> And your point is?
> 
> The syntax of the shell language (which is only implemented by zsh, not
> defined by it) precludes the use of infix operators.

The ability to set literal operands apart with whitespace is also
precluded by simple juxtaposition-based concatenation.

The thought just occurred to me that I could write a function which
concatenates its arguments.  I'll give that a try.

-- 
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-10-02 12:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-28 17:51 Multiline Anonymous Literal Strings Chris Johnson
2006-09-28 17:57 ` Michael Hernandez
2006-09-28 18:27   ` Chris Johnson
2006-09-28 18:26 ` Frank Terbeck
2006-09-29  4:52 ` Bart Schaefer
2006-10-02 12:42   ` Chris Johnson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).