这个问题已经有了答案:
Why does /bin/sh behave differently to /bin/bash even if one points to the other?
4个答案
mainfunction execSteps
一个接一个地执行,这些包的名称(只有名称,没有版本信息)存储在文本文件emerge --pretend $package
中。有些包可能需要额外配置package.use,package.license,执行stepFile
后会显示此类额外信息。main函数中的第二个while循环和emerge --pretend $package
旨在处理此类额外信息。
当出现一个特定的包时,它可能依赖于多个包。例如,function acceptPKGTypeItems
,在出现emerge --pretend ceph
之前,我需要出现10个以上的包。随着gentoo/linux的更新,可能会应用新版本的包。所以文本文件ceph
只包含我需要的包名,并且解析stepFile
的结果,我能够得到更新包。
在emerge --pretend $package
时,此while循环用于分析case 0)
的结果,例如emerge --pretend $line(which is from stepFile)
并获取其当前版本的依赖包,例如emerge --pretend ceph
,将其作为参数传递给dev-libs/boost-1.57.0
,因为包function emgRecursion
的依赖包dev-libs/boost-1.57.0
可能有自己的依赖包ceph
和dev-libs/boost-build-1.57.0
。
我的问题是当我在dev-libs/boost-1.57.0
处输入0时,while : command not found
中出现错误function emgRecursion
。这是另一种不同的贝壳吗?我在main函数中的第二个while循环之间添加了一对圆括号,这有助于从用户那里获得选择package.use、package.license或package.keywords的readin答案。我试图在第三个while循环之间添加另一对括号,同样的问题。我分别测试了case 0)
和emgRecursion
,它们都工作得很好并且正确。
有什么想法吗?非常感谢。
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
在主函数中循环时不会停止,
输出:
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
最佳答案
当我为测试emgRecursion
而创建时,将emgRecursion
以外的函数复制到另一个文件解决了这个问题。
我意识到这两个文件之间的区别(recursion
用于测试emgRecursion
,step
用于测试整个函数)是recursion
最初是用#!/bin/bash
创建的,而step
最初是一个没有任何第一行符号的纯shell文本文件,然后我向它添加了#!/bin/bash
。我认为bash
文本文件和shell
文本文件在语法上没有大的区别。事实上,他们完全不同。如果你像我一样把它们混在一起,那是浪费时间。
关于linux - 嵌套函数和while循环在bash中返回了while:未找到命令。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33882343/