LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Unix Shell Script Migration to UCP - expr syntax error (https://www.linuxquestions.org/questions/programming-9/unix-shell-script-migration-to-ucp-expr-syntax-error-4175665887/)

Gourav Sinha 12-13-2019 12:14 AM

Unix Shell Script Migration to UCP - expr syntax error
 
startLine=`grep -n 'SELECT ' $TempSQLOutput | awk -F":" '{ print $1}'`
startLine=`expr $startLine + 4`
endLine=`grep -n 'record(s) selected' $TempSQLOutput | awk -F":" '{ print $1}'`
endLine=`expr $endLine - 2`


This was the code and i am getting expr: syntax error in test autosys.Please suggest a solution?

NevemTeve 12-13-2019 01:08 AM

The last basically equals to expr - 2 as endLine is empty.

pan64 12-13-2019 03:26 AM

if it was bash you can use:
Code:

endLine=`expr ${endLine:-0} - 2`
would be nice to post the exact error message next time.

grail 12-13-2019 09:27 AM

I would also add that awk could get you the count and add 4 to it without the need for expr or grep


All times are GMT -5. The time now is 08:00 PM.