77问答网
所有问题
shell脚本 ,如果用 for in 语句,读取一行内容,急用,请高手回答。 for file in `ls -l --full-time ·
会自动以字符来分隔,而我想的每一行读取一行内容。怎么才能一次读取 ls -l 的一行内容。
举报该问题
推荐答案 推荐于2018-03-23
#!/bin/sh
#设置IFS环境变量,这个变量是用来定义分隔符类型的。默认的分隔符为空格、换行符、tab。
#在你的需求中,只需要设置IFS变量的内容为换行符。
#先存储IFS默认值
IFS_old=$IFS
IFS=$'\n'
for line in $(ls -l --full-time)
do
echo $line
done
#将IFS变量还原为默认值
IFS=$IFS_old
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://77.wendadaohang.com/zd/YqNIIY83q.html
其他回答
第1个回答 2011-07-26
只会一个笨办法,先创建一个文件,然后读文件
ls -l > tmp
while read line; do echo $line; done < tmp
第2个回答 2011-07-27
#!/bin/sh
ls -l | while read line
do
echo "start a line: " "$line"
done
第3个回答 2011-07-25
你的字符串要有规律就可以了比如加个&什么的
相似回答
linux作业题.请帮忙作一下(
shell脚本
编程)
答:
1、!/bin/bash dir=$1 cd $ dir shift
for
f in $@;do cat $f done 2、!/bin/bash for
file
in
`ls
-1 /root/a | grep ".*.c"`{ mv /root/a/$file /root/b } ls -lS /root/b 3.City = qw/Sydney Osaka Beijing.../ for($i=0,i<10;i++){ echo "$city[i...
shell脚本for
循环
答:
for
i in “$@” --》取所有位置参数,可以简写为for i 需要注意的是bash
shell
支持C式for循环。示例代码如下:!/bin/bash j=$1 for ((i=1; i=j; i++))do touch
file
$i echo file $i is ok done : 所有位置变量的内容 : 位置变量的个数 0: 文件名 : 所有位置变量的
内容
for...
在
shell脚本
中有个
语句
是if [ -d $1"/"$
file
],其中 $1"/"$file是什 ...
答:
1是指你运用这个
脚本
后跟着的第一个词组,比如你这个脚本命名为
shell
.sh,那么shell.sh /etc时,/etc代表$1 ,
for file in ` ls
$1 ` 这段语法是代表以file为变量枚举出$1也就是/etc下所有文件,For...In 声明用于对数组或者对象的属性进行循环操作。
如何用
Shell
逐行
读取
文件
答:
function
for
_in_file(){ For i in `cat $FILENAME` do echo $i done } 注释:这种方式是通过for循环的方式来
读取
文件的内容相比大家很熟悉了,这里不多说。对各个方法进行测试,看那方法的执行效率最高。首先我们用脚本(脚本见附件)生成一个70000行的文件,文件位置在/...
shell
中如何用
for语句
同时搜索两个文件夹内的所有文件,并进行文件比 ...
答:
先用ls命令枚举其中一个文件夹内的所有文件(用数组记录文件名)。cd 目录1 declare -a array=(
`ls
`)然后在枚举另一个文件夹时用
for
循环与数组元素逐个比较。cd 目录2 for
file
2 in do isFound=0 for file1 in ${array[*]} do if [ "$file2" = "$file1" ]; then diff -y --...
编写个
shell 脚本
将/usr/local/test 目录下大于100K 的文件转移到/tmp...
答:
!/bin/bash
for
file
in
`ls
/root`do if [ -f $file ]; then if [ `ls -l $file|awk '{print $5}'` -gt 10000 ]; then mv $file /tmp/ fi fi done 如果有什么不懂的话可以去看看《Linux就该这么学》这本书,非常适合新手学习Linux。
linux下开发
脚本
搜索子目录批量更改文件名
答:
设置 IFS 变量的命令需要放在
for
循环之前:IFS=$'\n'for
file
in
`ls
`do ...done 也可以直接使用 while read 命令一次
读取一行
到变量 file 中:ls | grep "*.txt" | while read file do ...done 使用 find 获取文件列表 之前的示例中,我们是通过 ls 命令来获取文件列表。该命令只能...
大家正在搜
shell脚本for循环语句
shell脚本if语句
shell脚本执行命令语句
linux中until语句的用法
shell for语句
shell循环语句while
shell中for循环语句
shell case语句
shell for in
相关问题
请教大神shell的for in语句中怎么使用多个变量
shell 中如何用for语句同时搜索两个文件夹内的所有文件...
Linux shell脚本for循环中in的[数据列表]从文...
linux shell脚本用while read逐行读取文本...
shell脚本循环读取更新了的文件并处理
shell编程中for file in $*; do是什么意...
用shell编程写一个for循环的九九乘法表 只能用一个fo...
在shell脚本中有个语句是if [ -d $1"/"$fi...