gpt4 book ai didi

linux - 遍历用户输入

转载 作者:太空宇宙 更新时间:2023-11-04 09:01:04 25 4
gpt4 key购买 nike

我有一个类似这样的 bash 脚本:

echo Enter a sentence
read line
for $x in $line ; do
echo $x
done

但是,它只回显整个输入,而不是按预期回显输入中的每个单词。这是为什么?有没有办法在不知道要输入的单词数的情况下解决这个问题,使用 for 循环,最好不要使用 read -a 选项,因为我知道如何使它工作,但我不相信满足已实现的要求。

谢谢外贸工作组

最佳答案

试试这个:

for x in $(echo "$line")

关于linux - 遍历用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21248515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com