From: pleb@iridescent.org
To: zsh-users@sunsite.dk
Subject: Problems with for loops and : modifiers
Date: Wed, 26 May 2004 01:55:52 -0700 [thread overview]
Message-ID: <p06100501bcda088b70c4@[192.168.0.9]> (raw)
I'm having problems doing something that should be simple. I want to iterate over a set of files in a directory and run some commands on those files. In the command I would like to strip the suffix of a filename away (ie basename) and add a new suffix.
I can do this interactively in zsh, using several of the different builtin "for" commands, but not in the following shell script.
Q:
1. Why do the "for" loops work interactively and get a syntax error in a script? To me a newline terminator is a newline terminator.
2. Maybe I have the sense of SHORT_LOOPS backward?
3. Why does the :r modifier work interactively and not in a script?
4. What are the suggested ways to do what I want to do?
zsh script follows.
Thanks in advance.
leb
#/bin/zsh
echo "one"
#files get echoed but :r is broken
for i in *.h; { echo $i:r ; }
echo "two"
#file get echoed, but :r is broken
for i in *.h
do
echo ${i}:r
done
echo "three"
# works perfectly when run interactively but gets an error in a script
#for i (*.h) echo $i:r
echo "four"
# works perfectly when run interactively but gets an error in a script
#foreach i ( *.h)
#echo $i:r
#end
#
--
Lawrence E. Bakst
pleb@iridescent.org
next reply other threads:[~2004-05-26 8:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-26 8:55 pleb [this message]
2004-05-26 9:22 ` Peter Stephenson
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='p06100501bcda088b70c4@[192.168.0.9]' \
--to=pleb@iridescent.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).