I am new to bash, trying to put together a little helper for myself.
I have a function and it seems it swallow new lines in the inner loop.
#!/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
I get this output:
tests/TestCase/Model/Table/SuggestionsTableTest.php
public function setUp public function tearDown public function testGetSuggestionsOneWord public function testGetSuggestionsMultipleWordsOneMatch public function testGetSuggestionsMultipleWordsMultipleMatches
What I want is to have all the functions in new line, what is exactly what I get in the outer for loop.