先说一下,我用的是这个:
以下是sh文件内容
********************************************
#!/bin/sh
FILENAME="$1"
cat $FILENAME | while read LINE
do
echo "$LINE"
done
********************************************
给你写了一个小例子,从一个文件读数据,设置环境变量:
数据文件data.txt包含三行:
aaa
bbb
ccc
------ test.sh ------
while read data; do
if [ $data = "ccc " ]; then
echo "[$data] "
export TTT= "$data "
fi
done < data.txt
----------------------
运行方式:
. test.sh
前面加一个点表示在当前shell进程运行,这样可以修改当前环境变量
*******************************************************************
*******************************************************************
*******************************************************************
*******************************************************************
shell读文件的十二种方法(收藏)Shell 2009-11-03 22:52:53 阅读503 评论1 字号:大中小
#!/usr/bin/ksh
#
# SCRIPT: 12_ways_to_parse.ksh.ksh
#
#
# REV: 1.2.A
#
# PURPOSE: This script shows the different ways of reading
# a file line by line. Again there is not just one way
# to read a file line by line and some are faster than
# others and some are more intuitive than others.
#
# REV LIST:
#