【发布时间】:2018-04-23 08:38:22
【问题描述】:
我在 Linux 上工作,需要计算目录中某些文件的总大小。
我编写了一个名为 cal.sh 的 bash 脚本,如下所示:
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
echo $line
done<`ls -l | grep opencv | awk '{print $5}'`
但是,当我执行此脚本./cal.sh 时,出现错误:
./cal.sh: line 6: `ls -l | grep opencv | awk '{print $5}'`: ambiguous redirect
如果我使用sh cal.sh 执行它,它似乎可以工作,但我会在输出结束时收到一些奇怪的消息:
25
31
385758: File name too long
为什么sh cal.sh 似乎有效? File name too long来自哪里?
【问题讨论】: