LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2221|回复: 3

shell中echo输入换行问题

[复制链接]
发表于 2006-12-13 15:58:40 | 显示全部楼层 |阅读模式
在以下两个shell中

  1. $pg forlist
  2. #!/bin/sh
  3. for loop in "orange red blue"
  4. do
  5.   echo "This is the fruit $loop"
  6. done

  7. $forlist
  8. This is the fruit orange red blue

复制代码



  1. $pg forparam
  2. #打印参数
  3. #!/bin/sh
  4. for params
  5. do
  6.   echo "You supplied supplied $params as s command line option"
  7. do

  8. $forparam file1 file2 file3
  9. You supplied supplied file1 as s command line option
  10. You supplied supplied file2 as s command line option
  11. You supplied supplied file3 as s command line option
复制代码



请问第一个例中了不是输出
This is the fruit orange
This is the fruit red
This is the fruit blue
 楼主| 发表于 2006-12-13 16:04:30 | 显示全部楼层
为什么第二个例子是每个FOR就是一行,还有
for loop in `ls`
do
  echo $loop
done


输出的当前文件也是每行一个
回复 支持 反对

使用道具 举报

发表于 2006-12-13 23:34:10 | 显示全部楼层

  1. [0 No.1999 huan@huan ~ ]$ for loop in "o r b"; do echo $loop; done
  2. o r b

  3. [0 No.2000 huan@huan ~ ]$ for loop in o r b; do echo $loop; done
  4. o
  5. r
  6. b

复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-12-14 11:20:27 | 显示全部楼层
晕,这么回事,我一直想到的是for loop in "o r b"中loop  是三个量orb,那它应该是直接是"o r b",要是

  1. $for loop in "or" "b";do echo $loop;done
  2. $or
  3. $b
复制代码

对不
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表