Bash Script Expr Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta expr syntax error in shell script Discuss the workings and policies of this site About Us Learn expr syntax error multiplication more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us unix shell script expr Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like shell script math expr you, helping each other. Join them; it only takes a minute: Sign up Syntax error expr up vote 2 down vote favorite Why does the following returning a syntax error: stringZ=abcABC123ABCabc echo `expr match "$stringZ" 'abc[A-Z]*.2'` This works on my ubuntu machine but when I try it on my mac running OS X 10.9.4 I get expr:
Shell Script Expr Example
syntax error? bash expr share|improve this question asked Aug 30 '14 at 23:00 rudolph9 4,00073163 Have you tried using echo $(expr match "$stringZ" 'abc[A-Z]*.2')? –Tom Fenech Aug 30 '14 at 23:04 @TomFenech same issue. –rudolph9 Aug 30 '14 at 23:07 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote accepted This seems like a bash version difference. The : syntax works on my OSX 10.9.4 machine (which has bash 3.2.51, not very current): echo `expr "$stringZ" : 'abc[A-Z]*.2'` share|improve this answer answered Aug 30 '14 at 23:08 Wm Annis 1084 1 Online documentation: developer.apple.com/library/mac/documentation/Darwin/Reference/… –glenn jackman Aug 30 '14 at 23:11 add a comment| up vote 2 down vote expr is quite old-fashioned. On newer bash you may prefer to use the more modern regular expression syntax: re='abc[A-Z]*.2' [[ $stringZ =~ $re ]] && echo ${#BASH_REMATCH} The =~ operator is available since bash version 3.0. For maximum compatibility across older versions of bash, it is recommended to store the
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.
Expr Syntax Error In Unix Shell Script
Search Forums Show Threads Show Posts Tag Search Advanced Search Unanswered expr index syntax error Threads Find All Thanked Posts Go to Page... learn linux and unix commands - unix shell scripting expr syntax error bash Error with expr - "expr: syntax error" Shell Programming and Scripting Tags expr: syntax error Thread Tools Search this Thread Display Modes http://stackoverflow.com/questions/25587446/syntax-error-expr #1 02-23-2012 jagari Registered User Join Date: Feb 2012 Last Activity: 21 May 2012, 10:09 AM EDT Posts: 6 Thanks: 3 Thanked 1 Time in 1 Post Error with expr - "expr: syntax error" Hi All, I'm writing a shell script in KSH, where I want to store the filename, total record count and actual http://www.unix.com/shell-programming-and-scripting/177534-error-expr-expr-syntax-error.html record count of all the source files. The source files reside in 4 different sub-folders under the same root folder. Below is code: Code: #!/usr/bin/ksh common_path_in="/interface_in/rsc" file_out="/interface_in/rsc/record_count.csv" tot_rec_count=-1 act_rec_count=-1 echo ${common_path_in} echo ${file_out} echo ${tot_rec_count} echo ${act_rec_count} set -A folders horizon mysteryshopper rcc reference echo ${folders[@]} for i in ${folders[@]} do ls -1 ${common_path_in}/$i/*.csv | xargs -n1 basename | while read filename do tot_rec_count=`wc -l ${common_path_in}/$i/*.csv | cut -f1 -d' '` echo ${tot_rec_count} act_rec_count=`expr ${tot_rec_count} - 1` echo ${act_rec_count} #echo "$filename,${tot_rec_count},${act_rec_count}" >> ${file_out} done done I'm getting output till the folder names, after that getting "expr: syntax error", for number of source files I've. Surprisingly among these errors only once I'm getting correct count outputs for the case, where the source folder contains only single data file. I've done the coding in vi editor and have not used MS editor. Please suggest. Regards, Jagari Remove advertisements Sponsored Links jagari View Public Profile Find all posts by jagari #2 02-23-2012 vbe Moderator Join Date: Sep 2005 Last Acti
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss http://askubuntu.com/questions/607240/why-am-i-getting-a-syntax-error-in-this-script the workings and policies of this site About Us Learn more about https://ubuntuforums.org/showthread.php?t=834263 Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up syntax error Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Why am I getting a syntax error in this script? up vote -2 down vote favorite When running the script below, I get an error: The script is: clear echo "Enter a num" read num if [ expr syntax error "$num" -ge 0]; then f=1 i=1 while [ $i -le "$num" ]; do f=`expr $f \* $i` i=`expr $i+1` done echo "The factorial of $num is $f" else echo "Enter positive number" fi Errors: Enter a num 5 prog4: 5: [: missing ] Enter positive number Thankyou bash share|improve this question edited Apr 9 '15 at 16:59 asked Apr 9 '15 at 15:59 Rahul Gohrani 12 2 I don't see a question here. I also don't see how this is an Ubuntu issue, as it's a pure generic coding question and belongs on Stack Overflow, not here. –Thomas Ward♦ Apr 9 '15 at 16:01 you forgot the backtick at the end of f=`expr .... And use indentation. –muru Apr 9 '15 at 16:02 2 I'm voting to close this question as off-topic because problems due to typos are hardly useful. –muru Apr 9 '15 at 16:06 2 @RahulGohrani bash questions are perfectly on topic here, don't worry. Just next time, write an actual question and use a more descriptive title. You should al
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community Wiki Other Support Launchpad Answers Ubuntu IRC Support AskUbuntu Official Documentation User Documentation Social Media Facebook Twitter Useful Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu Ubuntu Insights Planet Ubuntu Activity Page Please read before SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Specialised Support Ubuntu Servers, Cloud and Juju Server Platforms [ubuntu] [SOLVED] 'expr' command problems Having an Issue With Posting ? Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Results 1 to 5 of 5 Thread: [SOLVED] 'expr' command problems Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode June 19th, 2008 #1 Richard_ View Profile View Forum Posts Private Message Spilled the Beans Join Date Jun 2008 Location Durban Beans 13 DistroUbuntu 10.10 Maverick Meerkat [SOLVED] 'expr' command problems For some reason I'm unable to get expr to work with any parameters on strings that contain spaces. For example, This works: Code: $ temp='Fantastic' $ expr substr $temp 1 3 Fan Whereas this doesn't: Code: $ temp='Fantastic work' $ expr substr $temp 1 3 expr: syntax error The only difference is the added space. This problem occurs for all parameters of expr, including the length parameter. Suggestions welcome. Adv Reply June 19th, 2008 #2 pedro_orange View Profile View Forum Posts Private Message Extra Foam Sugar Free Ubuntu Join Date Nov 2007 Location UK Beans 772 DistroUbuntu 8.04 Hardy Heron Re: 'expr' command problems temp = "white space in string" echo temp: $temp Disclaimer: Yes I usually talk crap Adv Reply June 19th, 2008 #3 Richard_ View Profile View Forum Posts Private Message Spilled the Beans Join Date Jun 2008 Location Durban Beans 13 DistroUbuntu 10.10 Maverick Meerkat Re: 'expr' command problems Originally Posted by pe