bash - bash函数在循环内吞下新行
问题描述
我是 bash 的新手,试图为自己组装一个小帮手。
我有一个函数,它似乎在内部循环中吞下了新行。
#!/bin/bash
collect_results(){
egrep -o 'public function[ \t][ \t]*[a-zA-Z_]*' $@
}
get_function_name(){
cut -d' ' -f3 <<< $1
}
get_file(){
cut -d' ' -f1 <<< $1 | cut -f1 -d":"
}
IFS=$'\n'
RESULTS=( $(collect_results src/Model/Table/*) )
for RESULT in "${RESULTS[@]}"; do
FUNCTION=$(get_function_name $RESULT)
if ! [[ "$FUNCTION" =~ ^(beforeFind|buildRules|initialize|validationDefault|'')$ ]]; then
FILE=$(get_file $RESULT)
TMP=$(echo $FILE | sed "s/src/tests\/TestCase/")
TESTFILE=$(echo $TMP | sed "s/\.php/Test\.php/")
echo $TESTFILE
TESTRESULTS=$(collect_results $TESTFILE)
for TESTRESULT in "${TESTRESULTS[@]}"; do
echo $TESTRESULT
done
fi
done
我得到这个输出:
tests/TestCase/Model/Table/SuggestionsTableTest.php
public function setUp public function tearDown public function testGetSuggestionsOneWord public function testGetSuggestionsMultipleWordsOneMatch public function testGetSuggestionsMultipleWordsMultipleMatches
我想要的是在新行中拥有所有功能,这正是我在外部 for 循环中得到的。
解决方案
推荐阅读
- node.js - MongoDB:如何使用 expressjs 从所有集合中读取所有文档?
- regex - 匹配 char 之前的所有字符串并排除 n 个字符串
- javascript - 通过 SQL loader 加载数据并在 JSP 上显示时如何合并空单元格
- python - 我无法减少从天花板上落下的雨滴
- pycharm - Plotly by pycharm jupyter preview 不支持 WebGL
- javascript - 服务器端授权google OAuth 2.0,如何查看token?
- css - 在 Bootstrap 中更改标准选择器
- python - 开罗 get_data() 函数等效于 python 3
- django - 无需重定向的Django AJAX登录
- c# - 如何从包含反斜杠的字符串中解析 guid?