Arithmetic expression: expect primary:

I am trying to make a script in a shell that sleeps for an arbitrary period of time and then calls a python script. I'm doing it:

#!/bin/bash

now="$(date)"
printf "Current date and time %s\n" "$now"

maxdelay=25
delay=$(($RANDOM%maxdelay)) # pick an independent random delay for each of the 20 runs
echo $delay;
(sleep $((delay*60)); /usr/bin/python pythonscript.py) & 

But it does not work, this is the result:

Current date and time mar jun  9 00:02:10 CEST 2015
prueba.sh: 7: prueba.sh: arithmetic expression: expecting primary: "%maxdelay"

It works fine yesterday, but today I don't know why it fails

+4
source share
1 answer

It seems that you are using a script with dashinstead bash, perhaps because you are calling the script as

sh prueba.sh

instead

# prueba.sh must have exec permissions
# the shebang line is used to select the interpreter
./prueba.sh

or

bash prueba.sh

RANDOM- extension of bash; c dash, it is not special and is not assigned by default.

, $var, var , , . , var var , , 0.

Debian Ubuntu dash /bin/sh .

, bash dash :

$ bash -c 'unset foo;bar=25;echo $(($foo*$bar))'
bash: *25: syntax error: operand expected (error token is "*25")
$ dash -c 'unset foo;bar=25;echo $(($foo*$bar))'
dash: 1: arithmetic expression: expecting primary: "*25"
+8

All Articles