关于script的for语法

4 views
Skip to first unread message

wd

unread,
May 26, 2010, 9:11:48 PM5/26/10
to sh...@googlegroups.com, ubuntu-sg-zh
假设我有music 1.ape 和 music 2.ape
#!/bin/bash

apelist=$(ls | grep ape$)
echo -e $apelist

for apefile in $apelist
do
echo "File is $apefile"
done

然后用这个script来执行
得到的输出结果是
Music 1.ape Music 2.ape
File is Music
File is 1.ape
File is Music
File is 2.ape
我想要得到的结果是

Underground 5.0.ape Underground 6.0.ape
File is Music 1.ape
File is Music 2.ape
请问要怎么写呢?
先谢谢各位了

vivian huang

unread,
May 26, 2010, 10:07:48 PM5/26/10
to sh...@googlegroups.com, ubuntu-sg-zh
  #!/bin/bash

  apelist=$(ls | grep ape$)
  echo -e $apelist

  echo "$apelist"| while read apefile

                  do
                  echo  "File is $apefile"
                  done

2010/5/27 wd <wud...@gmail.com>

vivian huang

unread,
May 26, 2010, 10:11:44 PM5/26/10
to sh...@googlegroups.com
好几次这样抽风了,用户不存在?

2010/5/27 Mail Delivery Subsystem <mailer...@google.com>
尊敬的vivia...@gmail.com

此邮件旨在通知您:您尝试联系的网上论坛(“ubuntu-sg-zh”)可能并不存在,或者您没有向该网上论坛发帖的权限。以下是有关您无法发帖的详细原因:

 * 您可能未正确拼写该网上论坛的名称,或该网上论坛名称的格式错误。
 * 论坛版主可能已删除该网上论坛。
 * 您可能需要先加入该网上论坛才能获得发帖权限。
 * 该网上论坛可能没有开启发帖权限。

如果您有关于此网上论坛或其他任何 Google 网上论坛的问题,请访问帮助中心,网址为 http://groups.google.com/support/?hl=zh-CN_US

此致

Google Groups小组敬上



----- Original message -----

Received: by 10.114.68.10 with SMTP id q10mr3968714waa.9.1274926070222;
       Wed, 26 May 2010 19:07:50 -0700 (PDT)
Received: by 10.114.68.10 with SMTP id q10mr3968711waa.9.1274926070166;
       Wed, 26 May 2010 19:07:50 -0700 (PDT)
Return-Path: <vivia...@gmail.com>
Received: from mail-pv0-f171.google.com (mail-pv0-f171.google.com [74.125.83.171])
       by gmr-mx.google.com with ESMTP id u10si977653wak.2.2010.05.26.19.07.49;
       Wed, 26 May 2010 19:07:49 -0700 (PDT)
Received-SPF: pass (google.com: domain of vivia...@gmail.com designates 74.125.83.171 as permitted sender) client-ip=74.125.83.171;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of vivia...@gmail.com designates 74.125.83.171 as permitted sender) smtp.mail=vivia...@gmail.com; dkim=pass (test mode) header.i=@gmail.com
Received: by pvb32 with SMTP id 32so1051556pvb.30
       for <multiple recipients>; Wed, 26 May 2010 19:07:49 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
       d=gmail.com; s=gamma;
       h=domainkey-signature:mime-version:received:received:in-reply-to
        :references:date:message-id:subject:from:to:cc:content-type;
       bh=d9NExUCb/4gag7Tw4eDyJYAfLRcIPrtv5Oldden5V78=;
       b=VKy6ZTB++1P6lCbgOLIvxUPfriD5HLb5F893w0dXjSYewgACmX6axCLYduFwCkK30q
        siZmGmCFer10QzUSjbKPvVQqmgRB3oNQW6Ye2ehSiKQQV+i4BPSZuvdxTa/YIpUZqUx3
        RvzoO+9Jt0hBzEj7L50kkzHlTYr42pwiQvfYU=
DomainKey-Signature: a=rsa-sha1; c=nofws;
       d=gmail.com; s=gamma;
       h=mime-version:in-reply-to:references:date:message-id:subject:from:to
        :cc:content-type;
       b=rkhw07/THuUKKSiADMFcRpEQdPnMnMYhLdSBk6qnTvuADxq/sftPVPwwuS0XzMuEcY
        eVoXkf+7oNXbcFFYIOv4gniLDNe1e1RF/m/dEzXKcPmIeejEOs91BxzkniTD8/Oco5/A
        euOnsy5ve0XKIenhrqmLpcuQ18NEDwic/J8kQ=
MIME-Version: 1.0
Received: by 10.141.139.2 with SMTP id r2mr7299212rvn.83.1274926068965; Wed,
       26 May 2010 19:07:48 -0700 (PDT)
Received: by 10.141.35.2 with HTTP; Wed, 26 May 2010 19:07:48 -0700 (PDT)
In-Reply-To: <1274922708.14295.67.camel@Shanna>
References: <1274922708.14295.67.camel@Shanna>
Date: Thu, 27 May 2010 10:07:48 +0800
Message-ID: <AANLkTimhlrvmci4mRTRjc...@mail.gmail.com>
Subject: =?GB2312?B?UmU6IFtzaGx1Z10gudjT2nNjcmlwdLXEZm9y0++3qA==?=
From: vivian huang <vivia...@gmail.com>
To: sh...@googlegroups.com
Cc: ubuntu-sg-zh <ubuntu...@googlegroups.com>
Content-Type: multipart/alternative; boundary=0003255609ce74a3d0048789db35

 #!/bin/bash

 apelist=$(ls | grep ape$)
 echo -e $apelist

*  echo "$apelist"| while read apefile*

wd

unread,
May 26, 2010, 9:46:08 PM5/26/10
to sh...@googlegroups.com, ubuntu-sg-zh
真的可以阿 .. 请问下read是 ? 读取apefile变量的意思 ?
感谢

--
Sign by WD
http://wdstudio.blogbus.com

vivian huang

unread,
May 26, 2010, 10:29:13 PM5/26/10
to sh...@googlegroups.com, wud...@gmail.com
从stdin 读一行。
try 'man read" first~

2010/5/27 wd <wud...@gmail.com>

wd

unread,
May 26, 2010, 10:36:56 PM5/26/10
to vivian huang, sh...@googlegroups.com
从 echo "$apelist" 读一次stdin然后给apefile变量 ?
看了下man read ..

vivian huang

unread,
May 26, 2010, 11:52:24 PM5/26/10
to wd, sh...@googlegroups.com
'echo a | read b" 意思是"echo a" 的stdout 管道到"read b" 的stdin,read只管读stdin, 它不知道什么"echo a"。"|" 左右是两个并行进程。

2010/5/27 wd <wud...@gmail.com>

wd

unread,
May 26, 2010, 11:33:34 PM5/26/10
to vivian huang, sh...@googlegroups.com
明白了 .. 感谢
Reply all
Reply to author
Forward
0 new messages