Bash Script adding random newline
Okay, some background info. I've been writing a project in Bash, it essentially looks to see if you've done certain things on an ubuntu computer, and grades your performance, One of those things is answering questions, or disabling the guest account. The file that runs (init.sh) creates a new shell script(engine.sh) that actually does the grading depending on what the user wants to grade.
Now for the problem: All of the checks that I have output to the engine thus far have worked, but when I make this particular check (checks a file for a particular answer to have been given) it adds a newline to the engine.
functions involved:
createVuln() { type="$1" points=$2 var1="$3" var2="$4" var3="$5" var4="$6" var5="$7" test=$("$type" "test" "$var1" "$var2" "$var3" "$var4" "$var5") message="$("$type" "message" "$var1" "$var2" "$var3" "$var4" "$var5")" vuln="
if [ ${test} ]; then scorePoints \"$points\" \"$message\"
fi " echo "$vuln" >> vulns totalvulns=$(($totalvulns + 1)) totalpoints=$(($totalpoints + $points))
}
createForensics() { outputType="$1" question="$2" answer="$3" fileName="$4" if [ "$outputType" = "test" ]; then touch "$fileName" echo "Forensics Question:" > "$fileName" echo "$question" >> "$fileName" echo "" >> "$fileName" echo "ANSWER: " >> "$fileName" mv "$fileName" "/home/$sysUser/Desktop/" echo "\"\$(grep \"ANSWER: $answer\" \"/home/$sysUser/Desktop/$fileName\")\" != \"\"" elif [ "$outputType" = "message" ]; then echo "Solved ${fileName}" fi
}If I run this with
createVuln createForensics 8 'What is the UID of the user root?' 0 'Forensics Question 1'this outputs to the vulns file as:
if [
"$(grep "ANSWER: 0" "/home/user/Desktop/Forensics Question 1")" != "" ]; then scorePoints "8" "
Solved Forensics Question 1"
fi expected output:
if [ "$(grep "ANSWER: 0" "/home/user/Desktop/Forensics Question 1")" != "" ]; then scorePoints "8" "Solved Forensics Question 1"
fi Obviously, these newlines break the engine. the code I copied the forensics function from doesn't do this. The actual echos in the createForensics function do not output a newline when I run those from a terminal... In fact, the if statement even outputs correctly. So what is causing these newlines?!?
21 Answer
My Friend and I just realized: there was a problem with git not pushing a specific change that fixed this. There was a blank line that wasn't originally redirected to $fileName , and you can see there is a redirect now. When I committed and pushed got decided not to take that with it I guess.