linux - 使用 "while read"和 "for i in"导致不明确的重定向

标签 linux bash for-loop while-loop

# while read a b ; do echo $a $b ; done < `for i in \`cat users.txt\` ; do PHPVER=\`selectorctl --user-current --user=$i\` ; echo $i $PHPVER ; done | awk '{print $1, $2}' | sed 's/native/5.3/g'`

-bash: `for i in \`cat users.txt\` ; do PHPVER=\`selectorctl --user-current --user=$i\` ; echo $i $PHPVER ; done | awk '{print $1, $2}' | sed 's/native/5.3/g'`: ambiguous redirect

如果删除 while read 语句,输出为:

# for i in `cat users.txt` ; do PHPVER=`selectorctl --user-current --user=$i` ; echo $i $PHPVER ; done | awk '{print $1, $2}' | sed 's/native/5.3/g'

user1 5.4
user2 5.4
user3 5.3

所以我需要将这两列转换为一个变量,这样我就可以在这样的命令中运行它们:

# selectorctl --set-user-current=$b --user=$a

但是,当我添加 while read 语句时,它会引发不明确的重定向

最佳答案

确实不清楚你想做什么。您可能想做类似的事情

while read -r user; do
    read phpver rest < <(selectorctl --user-current --user="$user")
    output="$user $phpver"
    echo "${output//native/5.3}"
done < users.txt

Don't use for to read lines from a file .

关于linux - 使用 "while read"和 "for i in"导致不明确的重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36949789/

相关文章:

linux - 写入文件时循环的 Shell Bash 脚本

java - 如何将流重定向到简单的 Java 应用程序?

c++ for loop efficiency : body vs.事后思考

php - 使用循环插入数据时出现数据库错误

linux - 在多站点服务器上将 domain.com 直接定位到 www.domain.com

c - 如何处理 stat 和后续 mmap 之间的文件大小变化?

c++ - SIGABRT 在线程中访问内存时

python-3.x - 如何使用 gnu parallel 编写批处理命令?

linux - 在linux中,echo和pipe如何与docker一起工作?

R 将多个列表元素分配给同一个对象