LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2019, 12:14 AM   #1
Gourav Sinha
LQ Newbie
 
Registered: Dec 2019
Posts: 1

Rep: Reputation: Disabled
Exclamation 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?
 
Old 12-13-2019, 01:08 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
The last basically equals to expr - 2 as endLine is empty.
 
Old 12-13-2019, 03:26 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
if it was bash you can use:
Code:
endLine=`expr ${endLine:-0} - 2`
would be nice to post the exact error message next time.
 
1 members found this post helpful.
Old 12-13-2019, 09:27 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would also add that awk could get you the count and add 4 to it without the need for expr or grep
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting expr : syntax error while executing script priyanka28 Linux - Newbie 3 07-29-2013 05:00 AM
Anyone given UCP(ubuntu certified professional) exam? tanveer Linux - Certification 0 07-30-2012 08:32 AM
[SOLVED] test expr VS [ expr ] ashok.g Programming 3 12-03-2009 11:15 PM
How to multiply with expr? ( expr 3 * 4 doesn't work, though expr 3 + 4 does) lumix Linux - General 5 02-25-2009 05:31 PM
expr syntax error baosheng Programming 4 06-09-2005 03:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration