Linux 意外的行尾-dos2unix赢得';我修不好
我有以下代码:Linux 意外的行尾-dos2unix赢得';我修不好,linux,bash,syntax-error,Linux,Bash,Syntax Error,我有以下代码: #!/bin/bash set -o errexit set -o nounset set -o pipefail set -u se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'} ### gets the number of cell opt steps exec 0<"DEMLIR.out" while read -r line do gawk 'BEGIN{FS="OPTIMIZATION STEP:"} {prin
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
set -u
se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'}
### gets the number of cell opt steps
exec 0<"DEMLIR.out"
while read -r line
do
gawk 'BEGIN{FS="OPTIMIZATION STEP:"} {print $2}' | tr -s " "
done>results
sed -i '/^$/d' results
#sed -e 's/^[ \t]*//' results
step=$(tail -n 1 results)
echo "${step}"
### gets the number of steps in each geo_opt output
for i in $(seq 1 $step)
do
exec 0<"DEMLIR-GEO_OPT-$i.out"
while read -r line
do
gawk 'BEGIN{FS="OPTIMIZATION STEP:"} {print $2}' | tr -s " "
done>results_geo_$i
sed -i '/^$/d' results_geo_$i
step_geo=$(tail -n 1 results_geo_$i)
echo "${step_geo}"
### goes through each line in distance.out and prints distances to array
exec 0<"DEMLIR-GEO_OPT-$i-distance-1.coordLog"
while read -r line
do
for j in $(seq 0 $step_geo)
do
"$line" | se
paste -d' ' <(printf '%s\n' $j) <(se 1,5) <(se 2,5) <(se 2,8)
done
done
done>DEMLIR_task.txt
#/bin/bash
set-o errexit
集合-o名词集合
设置-o管道故障
set-u
se(){sed-n's/\s*r(“$1”).*r |=\s\+//p'}
###获取单元格opt步数
执行结果
sed-i'/^$/d'结果
#sed-e的/^[\t]*/'结果
步骤=$(尾部-n 1个结果)
回显“${step}”
###获取每个geo_opt输出中的步骤数
对于以美元为单位的i(seq 1$step)
做
exec 0results\u geo\u$i
sed-i'/^$/d'结果
步骤_geo=$(尾部-n 1结果_geo u$i)
回显“${step_geo}”
###在distance.out中遍历每一行,并将距离打印到阵列
exec 0问题在于:
se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'}
在}
前面需要分号或换行符。否则,它将被视为sed
参数的一部分。echo>>script\u step.sh
?@Cyrus不会在末尾添加一行额外的代码吗?将代码粘贴到shellcheck.netse
没有正确定义:se(){sed-n'.}
}
如果它本身不是一个单词,那么它就没有什么特殊性;实际上,它只是sed的参数的一部分,解析器永远看不到函数定义的结尾。@beliz:是的,它看到了。但我可能走错了方向。