Skip to main content

Questions tagged [expr]

expr - evaluate arguments as an expression

1 vote
1 answer
43 views

What is expr doing when processing arrays?

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
99 views

How to add mathematically the results of two commands in Linux

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
353 views

Understanding of the regexp match feature of the expr utility

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
278 views

Getting syntax error exception for “expr”

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

Set a variable to the result of a division and subtraction command

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,807
5 votes
3 answers
3k views

Convert only parts of a filename to uppercase

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
  • 193
0 votes
2 answers
591 views

My expr is being printed but not evaluated

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

'expr: syntax error: unexpected argument' - result from alias [duplicate]

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

How to read string as hex number in bash?

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

awk arithmetic differs from expr

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

Echo calculation to text file [duplicate]

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
125 views

Changing a variable value balance

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 this expr do in a shell script?

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.5k
2 votes
1 answer
967 views

expr and variables

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

shell - using expr “multiplication table”

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

15 30 50 per page