gpt4 book ai didi

linux - 嵌套函数和 while 循环在 bash 中返回 `while: command not found`

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:12:42 25 4
gpt4 key购买 nike

<分区>

主要的函数execSteps一个一个的执行emerge --pretend $package,这些包的名字(只有名字,没有版本信息)被保存在一个文本文件中步骤文件。一些包可能额外需要配置package.use,package.license,这种额外信息会在执行emerge --pretend $package后显示。 main 函数中的第二个 while 循环和 function acceptPKGTypeItems 就是为了处理这种额外的信息。

当出现一个特定的包时,它可能依赖于更多的包。例如emerge --pretend ceph,在ceph出现之前,我需要emerge 10多个包。随着 Gentoo/Linux 的更新,可能会应用新版本的软件包。所以文本文件 stepFile 只包含我需要的包名称,并解析 emerge --pretend $package 的结果,我能够得到更新的包出现。

case 0),这个while循环是为了解析emerge --pretend $line(which is from stepFile)的结果,例如 emerge --pretend ceph 并获取其当前版本的依赖包,例如 dev-libs/boost-1.57.0,将其作为参数传递给 function emgRecursion 因为 ceph 包的依赖包 dev-libs/boost-1.57.0 可能有自己的依赖包,它们是 dev-libs/boost-build- 1.57.0dev-libs/boost-1.57.0

我的问题是,当我在 case 0) 中输入 0 时,在 function emgRecursion 中出现错误 while : command not found。这是另一个不同的 shell 吗?我在 main 函数的第二个 while 循环之间添加了一对括号,这有助于从用户那里获得有关选择 package.use、package.license 或 package.keywords 的阅读答案。而且我尝试在第三个while循环之间添加另一对括号,同样的问题。我已经分别测试了 emgRecursionacceptPKGTypeItems,它们都可以正常工作。

有什么想法吗?非常感谢。

function acceptPKGTypeItems() {
...
}

function emgRecursion() {
local output="$(emerge --pretend "="$1 | grep "\[ebuild")"

       while read -r line;
       do

done <<<"$output"
}
function execSteps() {
local running=0
while read -r line;
do
if (( running )); then
if [[ $line = "#"* ]] && [[ "${line/"step"}" = "$line" ]]; then
continue
else
if [[ ! "${line/"step"}" = "$line" ]]; then
echo "====== approaching to the next step which is not available at this time."
break
else
( output="$(emerge --pretend $line | grep "\[ebuild")"
echo "**************** $line is ready for emerging ****************"
while read -p "Which type of package would you like to add new item to (1-packageuse 2-packagelicense 3-packagekeywords 0-exit and continue)? " choice; do
case "$choice" in
1) echo "**************** $line is ready for emerging"
acceptPKGTypeItems $PACKAGEUSE
echo "**************** package.use has been updated."

;;
2) echo "**************** $line is ready for emerging"
acceptPKGTypeItems $PACKAGELICENSE
echo "**************** package.license has been updated."

;;
3) echo "**************** $line is ready for emerging"
acceptPKGTypeItems $PACKAGEKEYWORDS
echo "**************** package.keywords has been updated."
;;
0) echo "**************** $line starts emerging"

while read -r element;
do
local str="${element#*"] "}"
str="${str%%" "*}"
echo " $str is an element that need to be emerged. "
emgRecursion "$str"
done <<<"$output"
echo "**************** $line has been emerged. ****************"
break
;;
*) echo "~~~~~~~~~~~~~~~~ Invalid input, try again. ~~~~~~~~~~~~~~~~"
;;
esac
done) </dev/tty
fi
fi
else
[[ $line = "#"$1 ]] && running=1
done <$STEPS
}

execSteps step2

在main函数中while循环什么都不会停止,输出:

livecd / # ./step1
* Last emerge --sync was 32d 23h 4m 58s ago.
**************** sys-cluster/ceph is ready for emerging ****************
Which type of package would you like to add new item to (1-packageuse 2-packagelicense 3-package.keywords 0-exit and continue)?0
**************** sys-cluster/ceph starts emerging ****************
dev-libs/libaio-0.3.110 is an element that need to be emerged.
* Last emerge --sync was 32d 23h 5m 3s ago.
./step1: line 48:        while: command not found
./step1: line 49:        : command not found
./step1: line 50:                str=dev-libs/libaio-0.3.110: No such file or directory
Take a look at what dev-libs/libaio-0.3.110 looks like.
./step1: line 77:        done: command not found
sys-libs/libunwind-1.1 is an element that need to be emerged.
* Last emerge --sync was 32d 23h 5m 5s ago.
^C

Exiting on signal 2

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