expr

macOS Mojave version 10.14.1 bash-3.2 expr: syntax error

こ雲淡風輕ζ 提交于 2021-02-05 08:13:29
问题 I meet such error: expr: syntax error and my script is: #!/bin/bash echo `expr index "sarasara" a` how to fix it. 回答1: $ man expr gives this at the end: According to the POSIX standard, the use of string arguments length , substr , index , or match produces undefined results. In this version of expr , these arguments are treated just as their respective string values. In other words, macOS' expr does not support index . 来源: https://stackoverflow.com/questions/53701873/macos-mojave-version-10

Is it possible to set a cron job or bash script to run X minutes from now?

寵の児 提交于 2021-02-04 20:50:22
问题 I understand I can set a cron job to run every 5 minutes with crontab -e by adding a line such as: */5 * * * * /path/to/script.sh . Is it possible to get the system time in minutes using date +"%M" for example, and then set a cron job to run at date +"%M" plus 5 minutes? I know I can get date +"%M" + 5 via the following process: $ MIN=`date +"%M"` $ export MIN $ expr $MIN + 5 Is it possible to use this to set a cron job or script to run at "current time in minutes" plus "X minutes"? I could

MongoDB unknown top level operator: $expr nodejs

天大地大妈咪最大 提交于 2020-01-06 06:51:33
问题 I tried finding solution for this online, but no success. This is the code: Invoice.count( { $expr: {$gt: [ "$totalAmount", "$remainingDebt" ]} } ).exec(callback); where totalAmount and remainingDebt are fields in schema Invoice. The result I get is: "unknown top level operator $expr". I am using mongoose 5.0.11 and mongo lab. Any ideas? 回答1: which version you are Using for the MongoDB since MLab is Providing the Maximum 3.6 version of the Mongo so you need to either modify the Query or

Multiplication with expr in shell script

拥有回忆 提交于 2019-12-17 19:44:15
问题 I am making a basic calculator to add, subtract, multiply, and divide. Addition works, but not multiplication. When I attempt to multiply, I get the "You did not run the program correctly" response: $ ./calculator 4 + 5 9 $ ./calculator 4 * 5 You did not run the program correctly Example: calculator 4 + 5 I've searched around on google, where I found the \\* code, but still doesn't work. Can someone provide me with a solution or explanation? Here is my code #!/bin/bash if [ $# != 3 ]; then

How to fix 'Unrecognized expression $round' while applying it to stored data in pipeline using mongodb $and condition with $lookup

老子叫甜甜 提交于 2019-12-13 17:26:16
问题 I have applied precision to the data coming from DB, while viewing it in browser using Angular 7. Front End: Angular 7 Back End: Java and Mongodb before precision (in db): 100.9999 after precision visible to user(2 after decimal): 101.00 There is a search functionality on UI in which a user can write any amount range. Scenario 1: User inpu t: 100 to 100 Result: no records found (expected) Scenario 2: User input: 101 to 101 Result: no records found (should have found 1 record according to user

bash- find average of numbers in line

一曲冷凌霜 提交于 2019-12-02 05:03:26
问题 I am trying to read a file line by line and find the average of the numbers in each line. I am getting the error: expr: non-numeric argument I have narrowed the problem down to sum= expr $sum + $i , but I'm not sure why the code doesn't work. while read -a rows do for i in "${rows[@]}" do sum=`expr $sum + $i` total=`expr $total + 1` done average=`expr $sum / $total` done < $fileName The file looks like this (the numbers are separated by tabs): 1 1 1 1 1 9 3 4 5 5 6 7 8 9 7 3 6 8 9 1 3 4 2 1 4

bash- find average of numbers in line

可紊 提交于 2019-12-02 01:06:00
I am trying to read a file line by line and find the average of the numbers in each line. I am getting the error: expr: non-numeric argument I have narrowed the problem down to sum= expr $sum + $i , but I'm not sure why the code doesn't work. while read -a rows do for i in "${rows[@]}" do sum=`expr $sum + $i` total=`expr $total + 1` done average=`expr $sum / $total` done < $fileName The file looks like this (the numbers are separated by tabs): 1 1 1 1 1 9 3 4 5 5 6 7 8 9 7 3 6 8 9 1 3 4 2 1 4 6 4 4 7 7 With some minor corrections, your code runs well: while read -a rows do total=0 sum=0 for i

Multiplication with expr in shell script

99封情书 提交于 2019-11-28 11:16:55
I am making a basic calculator to add, subtract, multiply, and divide. Addition works, but not multiplication. When I attempt to multiply, I get the "You did not run the program correctly" response: $ ./calculator 4 + 5 9 $ ./calculator 4 * 5 You did not run the program correctly Example: calculator 4 + 5 I've searched around on google, where I found the \\* code, but still doesn't work. Can someone provide me with a solution or explanation? Here is my code #!/bin/bash if [ $# != 3 ]; then echo You did not run the program correctly echo Example: calculator 4 + 5 exit 1 fi if [ $2 = "+" ]; then