BASH的IO操作

sh/bash/dash/ksh/zsh等Shell脚本
回复
yuffey
帖子: 193
注册时间: 2007-09-06 16:24
来自: 中国上海
送出感谢: 0
接收感谢: 0

BASH的IO操作

#1

帖子 yuffey » 2007-11-10 15:48

Bash从控制台和文件中输入时,有点不一样喽,看看例子就明白。。

从文件中输入输出
more data_file
1 2 45
33
44

代码: 全选

# Read from data file: 
echo "Numbers are in one line space separated:" 
read a b c < data_file 
echo a = $a 
echo b = $b 
echo c = $c


echo "Numbers are stored one per line:" 
{ 
       read a 
       read b 
       read c } < data_file 
echo a = $a 
echo b = $b 
echo c = $c

  • Numbers are in one line space separated:
    a = 1
    b = 2
    c = 45
    Numbers are stored one per line:
    a = 1 2 45
    b = 33
    c = 44
yuffey
帖子: 193
注册时间: 2007-09-06 16:24
来自: 中国上海
送出感谢: 0
接收感谢: 0

#2

帖子 yuffey » 2007-11-10 15:54

得出的结果是:
Read是分行读入变量,那么变量赋值就是分行得,否则就不是。
回复

回到 “Shell脚本”