0

我正在尝试收听管道并编写此代码,但我得到了模棱两可的重定向错误,这是为什么呢?

pipe = "./$1"

# trap enables to execute a command when a signal is sent to your script
trap "rm -f $pipe" EXIT


if [[ ! -p $pipe ]]; then
    mkfifo $pipe
fi


while true
do
    if read line <$pipe; then
        if ["$line" == 'EXIT'  -o  "$line" == 'exit' ]; then
            break
        else 
            echo $line
        fi
    fi
done
4

1 回答 1

3

我怀疑您的第一行因错误而失败:

管道:找不到命令

因为变量赋值bash不支持变量名和=符号之间的空格。因此,$pipe未定义并read line < $pipe失败。尝试:

pipe="./$1"
于 2012-07-30T10:10:22.400 回答