I studied this article called Returning Values from Bash Functions. Data
Lorem.
\begin{document}
hello
\end{document}
Case #1 which does not work
Code
#!/bin/bash
function getStart {
local START="$(awk '/begin\{document\}/{ print NR; exit }' data.tex)"
}
START2=$(getStart)
echo $START2
which returns falsely an empty line.
I expect 1
.
Why does the script return an empty line?
Case #2 which works
Code
#!/bin/bash
function getStart {
local START="$(awk '/begin\{document\}/{ print NR; exit }' data.tex)"
echo $START
}
getStart
which prints correctly 1
.
Output of choroba's answer
#!/bin/bash
function getStart {
local START="$(awk '/begin\{document\}/{ print NR; exit }' data.tex)"
echo $START
}
START2=$(getStart)
echo $START2
gives the linenumber only once, which is not the expected result. I think it should do it twice.