Artificial intelligent assistant

Shell script - Couldn't find 'fi' for this 'if' I have found this error alongside couple more. I believe that the nesting is not quite all right or the for is not correctly indented or without some semicolon. Either way I have tried for quite some time to figure it out, but to no avail. Here is the code: if [ "${runcmd}" != "echo" ]; then statusmsg "Kernels built from ${kernelconf}:" kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath}) for kern in ${kernlist:-netbsd}; do [ -f "${kernelbuildpath}/${kern}" ] && \ echo " ${kernelbuildpath}/${kern}" done | tee -a "${results}" fi It is part of a build.sh file.

The

`var=value cmd ar1`

syntax doesn't quite seem to work if `cmd` is a for loop (in neither `bash` nor `sh`).

Both `sh` and `bash` give syntax errors for:


foo=bar for f in ${foo:-BAR}; do echo $f; done


which is what you're esentially doing.

(

* sh: 1: for: not found
* bash: syntax error near unexpected token `do'



)

And that error seems to result in a `couldn't find fi` error in your case;

Setting the variable on a separate line fixes the syntax error:


kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
for kern in ${kernlist:-netbsd}; do #...


**Note:**

I would just write `"$kernelbuildpath/$kern"` instead of `"${kernelbuildpath}/${kern}"` if I were you. There's no technical reason for the curlies.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d6ce97ffa491675b520e393745d10e28