linux - 意外的行尾 - dos2unix 不会修复它
问题描述
我有以下代码:
#!/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
我尝试运行这个程序,但我一直unexpected end of line error
在第 53 行。我看到这个问题已经有了答案,但是当我尝试时dos2unix
它说
dos2unix: converting file script_step.sh to Unix format...
但就是这样。当我再次运行代码时,它不会工作。
我预计最后一个 for 循环会出现一些错误,所以如果你看到一些错误,你也可以指出它们。但是,如果它们与原始问题无关,那么您可以忽略它们。
解决方案
问题在这里:
se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'}
在 . 之前需要一个分号或换行符}
。否则,它被视为sed
论点的一部分。
推荐阅读
- conv-neural-network - 图像数据增强和训练
- javascript - 如何防止在 React Native 功能中单击按钮时刷新页面
- python - 如何替换表中的 NaN 以获取每日股票收益?
- python - 什么原因以及如何防止 BigQuery 错误:调用时超过 120.0s 的截止日期
- python - “UnboundLocalError:分配前引用的局部变量'args'”以及如何解决?
- java - Quarkus 1.13.7 + OptaPlanner 8.7.0 error - Illegal char in quarkus-core-deployment-1.13.7.Final.jar
- c - 什么是 __asm_rep_movsb_memcpy() 和 __asm_rep_stosb_memset() 之类的?
- android - android sdk 位置不能位于文件系统根目录
- c++ - 在 C++ 中重载 << 运算符需要朋友
- r - 如何在 R data.table 中有效地实现可变过滤条件?