zsh-users
 help / color / mirror / code / Atom feed
From: Stephane CHAZELAS <Stephane_Chazelas@yahoo.fr>
To: Meino Christian Cramer <Meino.Cramer@gmx.de>
Cc: duvall@comfychair.org, zsh-users@sunsite.dk
Subject: Re: Sorting files
Date: Fri, 5 Aug 2005 11:47:33 +0100	[thread overview]
Message-ID: <20050805104732.GA16537@artesyncp.com> (raw)
In-Reply-To: <20050805.050146.74727615.Meino.Cramer@gmx.de>

On Fri, Aug 05, 2005 at 05:01:46AM +0200, Meino Christian Cramer wrote:
[...]
> > >     print -l **/*(.oL)
[...]
> > Should be:
> > 
> > print -rl -- **/*(.oL)
[...]
> This gave me no sorted output...sorry :O)


I was just pointing out that

print -l arbitrary list of file names

is not correct. print without -r is to print a text that is in
the form "text with \t \n... escape sequences" like in C string
constants. That's an old design error in shells inherited from
ksh to have that as the default behavior. For a correct way, see
perl for instance where \t, \n are expanded at the language
level (or by the double quotes if you like).

In perl,

$var = "\t"

assigns a <Tab> character to $var and print $var prints the
content of $var. ($var = '\t' assigns "\" and "t" to $var).

In shells,

var="\t"

assigns the "\" and "t" characters to $var and print "$var"
prints the expansion of the "\t" escape sequence, i.e. a <Tab>
character.

ksh93, bash and zsh have the cumbersome:

var=$'\t'

that does the same as perl's "\t", but print (and echo) are
still /broken/ and need the "-r" (and -n to prevent adding a
newline character) to print strings asis.


Without --, the list can be options or arguments, while you
definitely mean them to be arguments there.

Another annoying thing with print -l is that without arguments,
it still prints an empty line as if it had been given an empty
argument.

So that to print arguments one per line, you actually need:

correct_print-l() {
  (( $# == 0 )) || print -rl -- "$@"
}

or to be portable (POSIX):

correct_print_l() {
  [ "$#" -eq 0 ] || printf '%s\n' "$@"
}

-- 
Stephane


  reply	other threads:[~2005-08-05 10:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-04 18:38 Meino Christian Cramer
2005-08-04 18:48 ` Mikael Magnusson
2005-08-04 19:10   ` Meino Christian Cramer
2005-08-04 19:18     ` Danek Duvall
2005-08-04 20:41       ` Stephane Chazelas
2005-08-05  3:01         ` Meino Christian Cramer
2005-08-05 10:47           ` Stephane CHAZELAS [this message]
2005-08-04 19:14 ` Christian Schneider
2005-08-04 21:19   ` Jens Kubieziel
2005-08-05  3:06   ` Meino Christian Cramer
2005-08-04 19:51 ` Christian Taylor
2005-08-05 10:51   ` zzapper
2005-08-05 12:57     ` Christian Taylor
2005-08-05 14:41     ` Meino Christian Cramer
2005-08-06  5:38     ` Summary: " Meino Christian Cramer
2005-08-06  9:22       ` Christian Taylor
2005-08-05 12:52 ` DervishD
2005-08-05 14:01   ` Meino Christian Cramer
2005-08-05 14:29     ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050805104732.GA16537@artesyncp.com \
    --to=stephane_chazelas@yahoo.fr \
    --cc=Meino.Cramer@gmx.de \
    --cc=duvall@comfychair.org \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).