Questions tagged [expr]

Command-line expression evaluator

The expr utility evaluates expressions and writes the result on standard output.

See the FreeBSD Man page.

102 questions
1
vote
2 answers

How to use `expr` when there's an optional substring in the regex?

I want to find the go[^ ]+ inside these two strings using expr. The output should be 1.17.6 and 1.18-becaeea119. go version go1.17.6 linux/amd64 go version devel go1.18-becaeea119 Tue Dec 14 17:43:51 2021 +0000 linux/amd64 However, the devel part…
Nato Boram
  • 4,083
  • 6
  • 28
  • 58
1
vote
3 answers

newprime.sh: line 14: [: 0+1: integer expression expected

what's wrong with my code? I am trying to print prime numbers upto n digits echo Enter Number read num for (( i=2; $i <= $num ; i++ )) do c=0 for (( j=2; $j <= $i ; j++)) do …
Sana Mev
  • 111
  • 8
1
vote
1 answer

How to send form value to node/express to search database?

I've got a pre populated form with gps coordinates and I am trying to search a database.
Yonder
HMCS
  • 35
  • 2
1
vote
1 answer

macOS Mojave version 10.14.1 bash-3.2 expr: syntax error

I meet such error: expr: syntax error and my script is: #!/bin/bash echo `expr index "sarasara" a` how to fix it.
kailee
  • 33
  • 1
  • 5
1
vote
1 answer

ANTLR4 repeating ANDs

With the following rule: expr: '(' expr ')' #exprExpr | expr ( AND expr )+ #exprAnd | expr ( OR expr )+ #exprOr | atom #exprAtom | ID #exprId ; atom: '[' ID RELOP INT ']' ; I would like to allow statements like this: [a<3] and…
Mike75
  • 504
  • 3
  • 18
1
vote
1 answer

Why should arithmetic operators be padded by space in expr?

Using expr to evaluate an expression in bash, the following happened bash-3.2$ expr 1+1 1+1 bash-3.2$ expr 1 + 1 2 Why should the plus sign be padded by space for it to be interpreted as mathematical operation?
mc9
  • 6,121
  • 13
  • 49
  • 87
1
vote
0 answers

How to send List of Expression to Aggregate Function in Spark JAVA API

I'm trying to execute below code using Spark JAVA api. sampleDS=sampleDS .select(col("column1"),col("column2"),col("price1")col("price2")) .groupBy(col("column1"),col("column2")) …
John Humanyun
  • 915
  • 3
  • 10
  • 25
1
vote
1 answer

TCL ternary expr does processing of output

It involves TCL 8.6, and is derived from answer I got on issue Nitpicking: Tcl storing in a variable or not, for speed, in procedures So, consider this code: proc me1 { in1 in2 } { if { $in1 > $in2 } { return [ k $in1 ] } else { …
user1134991
  • 3,003
  • 2
  • 25
  • 35
1
vote
2 answers

How do a test if a parameter is a number in a script using expr?

I've been trying to figure out a way to test if a parameter is a number using the command expr. In my script so far I've written: expr $1 + 1 2>/dev/null if [ $? -eq 2 -o $1 -lt 0 ] then echo "$1 is not a positive integer" >&2 exit…
AlexT
  • 589
  • 2
  • 9
  • 23
1
vote
1 answer

BSD expr difference with GNU expr

Does any one know why expr "4" : '-\?[0-9]\+$' returns 0 on Mac OS X and 1 on Linux? Fact: Mac uses BSD expr Linux uses GNU Sorry, I originally typed expr "4" : '-\?[0-9]+$'
frankliuao
  • 380
  • 1
  • 4
  • 14
1
vote
2 answers

what is wrong in this bash expression

I got one error in the first expr nmin =$(expr ($nr-1)*31) nmax =$(expr ($nr*31)-1) array=`ls *d03_*` # specify files to be subsetted for name in ${array[@]:nmin:30} After reading the documentation seems like one space or really minor thing…
gis20
  • 1,024
  • 2
  • 15
  • 33
1
vote
2 answers

Why doesn't compiler automatically brace expr?

I was reading through Donal Fellows' excellent explanation on why you should brace your expr. It makes me wonder why doesn't the tcl compiler automatically brace {} the expr? What are conditions under which this automatic bracing will fail?
Anand
  • 1,122
  • 3
  • 20
  • 33
1
vote
1 answer

TCSH: convert a sed output to a expr sum

Hi im having troubles with the following code: #|/bin/tcsh TOTALMOS=`grep -v "Last MO:" x.log | grep "Total: .* MOs" | grep "Total: .* MOs" | awk '{ print $2 }' | tr '\n' ' ' | awk '{ print $1 }'` RADIONO=`grep -n "get radio no" x.log | cut -f1…
1
vote
1 answer

Ast parsing of ast.Expr types

There is something I do not understand about the lineno offset that's being calculated by the ast module. Usually when I get the lineno of some ast object, it gives me the first line the object is encountered. For example in the below case, the…
karpet22
  • 51
  • 3
1
vote
2 answers

Using Perl to strip everything from a string except HTML Anchor Links

Using Perl, how can I use a regex to take a string that has random HTML in it with one HTML link with anchor, like this: Whatever Example and it leave ONLY that and get rid of everything else? No…
Richard Jones
  • 45
  • 1
  • 8