I'm stuck on a rather simple problem with the increment of a variable that gets printed out as consecutive strings to a file.
Here's a sample of the code:
#!/usr/bin/bash
_SesT=`date +%Y\/%m\/%d\ %H\-%M\-%S`
n="0"
Execution_IT(){
while read $3
do
((n++))
printf $n
done < ExecLog.txt
}
echo "test" && echo $_SesT
printf "Execution $(Execution_IT) Started $_SesT\r\n" >> ExecLog.txt
The problem is that the output gets formatted like this:
Execution Started 2016/02/08 19-06-44
Execution 1 Started 2016/02/08 19-06-44
Execution 12 Started 2016/02/08 19-06-44
Execution 123 Started 2016/02/08 19-06-45
Execution 1234 Started 2016/02/08 19-06-45
Execution 12345 Started 2016/02/08 19-06-45
Execution 123456 Started 2016/02/08 19-06-46...
... instead of:
Execution 1 Started 2016/02/08 19-06-44
Execution 2 Started 2016/02/08 19-06-44
Execution 3 Started 2016/02/08 19-06-45...
This is the most working version I got to after trying cut -d; awk; sed; and even C-like syntax for loop. There was a version very similar to this with while read line, but the output was exactly the same. Any suggestions will be well-appreciated.
Execution_IT? and what isSession_IT?dateat every line, or just once at the beginning of the script?read $3? You don't have any variable name passed to the function as$3(as when you call the function it's with no arguments at all), and if you expectreadto be setting the value in$3... well, it doesn't work that way.$3doesn't mean column-3 in bash; it's only awk where it means that.