Skip to main content

Questions tagged [expr]

expr - evaluate arguments as an expression

Filter by
Sorted by
Tagged with
4 votes
1 answer
414 views

The following: expr "/foo" : "/" Results in a syntax error. I don't understand why? These variations do not cause a syntax error: expr "/foo" : "/*" expr "...
engber's user avatar
  • 51
1 vote
1 answer
105 views

I have a BASH script problem that I've narrowed down but I can't understand what I'm seeing. I want to get a substring of an array in a succinct way. Here's what I'm seeing in bash, with 'set -x' so ...
John Hawthorne's user avatar
2 votes
2 answers
128 views

In a Debian Linux shell, I am trying to add the results of two separate commands so that I know the sum of both. I already tried: echo $(expr $(du -sh /srv/mysql) + $(du -sh /srv/www)) and ...
davidman77's user avatar
4 votes
1 answer
482 views

Could anyone help me to understand how the regex match works with the expr utility? I've read its man page and below is an excerpt: STRING : REGEXP anchored pattern match of REGEXP in STRING But I ...
Fajela Tajkiya's user avatar
0 votes
1 answer
308 views

I have an xml file which looks like below INPUT XML FILE <ReconSummary> <entryName>Total Deep</entryName> <Code>777</Code> <License>L</License> <Tran>...
DEEP MUKHERJEE's user avatar
3 votes
3 answers
3k views

I am trying to get the difference of 2 dates in epoch form and convert the number back to days: EXPIRYEPOCH=$(date --date="$EXPIRYDATE" +%s) TODAYEPOCH=$(date --date="$TODAYSDATE" +...
Kahn's user avatar
  • 1,827
5 votes
3 answers
3k views

In a shell script program, I need to convert the filenames to uppercase if the converted filename does not already exist. In this particular case I need to change only the basename to uppercase ...
Esha's user avatar
  • 203
1 vote
2 answers
621 views

The code for the script is: echo "Years:" read age x=`expr $age*365` echo -e $x The output when I call this script from the command line is as follows: Years: (say I put 20) 20*365 Why is it not ...
Hailey White's user avatar
0 votes
1 answer
5k views

I recently added an alias to my .bash_aliases file: alias runhole="perfect && cd data_series_test && doa=$(ls -1 | wc -l) && a=$(expr $doa / 2 ) && perfect && ...
Adrian Barbuio's user avatar
8 votes
2 answers
14k views

I have the bash line: expr substr $SUPERBLOCK 64 8 Which is return to me string line: 00080000 I know that this is, actually, a 0x00080000 in little-endian. Is there a way to create integer-variable ...
DenisNovac's user avatar
1 vote
1 answer
1k views

There are some contrast output between awk arithmetic and expr. Example expr 11111111111111111111 / 22 gives 505050505050505050 but with awk: echo '11111111111111111111' | awk '{q=$1/22;;print q}' ...
user avatar
1 vote
2 answers
2k views

I am working on a project to calculate my overtime at work with a shell script. I have two inputs and want to find if my number is over 800 = 8 hours; if it is bigger, then it has to print out the ...
peter's user avatar
  • 17
0 votes
1 answer
138 views

I am practicing unix, self learning so I done some basic coding of creating a cash machine. so far I have done the following and need some guidance on the final hurdle I am stuck on how I can update ...
Kam's user avatar
  • 121
2 votes
1 answer
2k views

What does the following do exactly? newProg=`expr "${newProg}" : ".* -> \(.*\)$"` if expr "x${newProg}" : 'x/' >/dev/null; then prog="${newProg}" else progdir=`dirname "...
Jim's user avatar
  • 10.7k
2 votes
1 answer
992 views

How do I run the script: ./script.sh 1 \* 2 Eventually: ./script.sh 1 '*' 2 How does my script look like: args="$@" # the first line of the script result=$(($args)) echo "$args = $result" Does it ...
SantaXL's user avatar
  • 375
1 vote
2 answers
7k views

I'm learning shell to create a multiplication table, I write code like that: #!/ in/bash for i in 1 2 3 4 5 6 7 8 9 do for j in 1 2 3 4 5 6 7 8 9 do if [ $j -le $i ] ...
Lost Vanity's user avatar
0 votes
1 answer
3k views

I know that both of them can do simple arithmetic. I'm wondering when it will be easier to use one versus the other. I know that expr evaluates an expression from its arguments, while bcl evaluates ...
Hurricane Hamilton's user avatar
2 votes
1 answer
2k views

I am doing add operation as #!/bin/sh a=10 b=20 c='expr $a + $b' echo "$c" echo "$a" echo "$b" but it is showing output as expr $a + $b 10 20 what is wrong with expr
user183924's user avatar
2 votes
3 answers
3k views

I am trying to write a script to get a random, even hex number. I have found the the openssl command has a convenient option for creating random hex numbers. Unfortunately, I need it to be even and my ...
resu's user avatar
  • 133
1 vote
2 answers
231 views

I have a source code to find a number of words and characters in a file: #!/bin/bash w=0 cc=0 for i in `cat $1` do j=$i echo $j w=$(($w+1)) c=`expr $j:'.*'` cc=$(($cc+$c)) done echo "no of characters"...
Stranger's user avatar
  • 337
21 votes
3 answers
51k views

In shell script we can substitute expr $a*$b with $(($a+$b)). But why not just with (($a+$b)), because in any resource it is written that (()) is for integer computation. So we use $(()) when ...
Stranger's user avatar
  • 337
2 votes
2 answers
2k views

I need a explanation of why: $test=`expr "hello" : "\([a-z]*\)"`; echo $test would print out hello, where as: $test=`expr "hello" : "hel"`; echo $test would return the number of characters matching. ...
夢のの夢's user avatar
-1 votes
1 answer
454 views

I am trying to sum a column for each vendor in a loop. I apologize for the vagueness. I will try to explain. It is suppose to read from a file and based on the vendor name total the field labeled ...
Sevenreindeer's user avatar
0 votes
1 answer
285 views

I am having a really a hard time to evaluate conditional strings and numbers. After hours of reading and trying with (my Beginners Guide) I keep getting the error msgs like syntax error in conditional ...
snahl's user avatar
  • 103
1 vote
1 answer
3k views

I was working on extraction of sub-string from the beginning & at the end of the string. I experimented with and with out ".*" $expr "ab1cd1efgfedcbaAAAA" : ".*\(1[a-l]*\)" # Result: 1efgfedcba ...
Sudhish Vln's user avatar
0 votes
3 answers
948 views

Can anybody give me the difference between the following two commands in the context of escaping parentheses, or refer some document that would clear my doubt. string=abcABC123ABCabc $ echo `expr ...
Sudhish Vln's user avatar
80 votes
7 answers
154k views

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
Nicolas Raoul's user avatar