I am getting this really weird error despite of the fact that the same script runs fine on one platform (Arch linux) but not on my other mobile platform (Maemo Linux). I'll pass here the relevant part of the code with the line numbering:

41 for DIR in $DIRS
42 do
43 tempdir=$DIR/
44 tempval=$(stat -c %Y $tempdir)
45 echo $tempval
46 if (( $tempval > $(date +%s) - 3600*24*30 )); then
47     echo "I am done basically. Exiting..."
48     exit
49 else
50     continue
51 fi
52 done

In the code above DIRS is a list which contains names of directories. In this loop i am trying to find one directory of the list which is newer than 30 days old and if i find one i exit the script.

Line 45 is put there for debugging purposes basically.

I am getting the error below:

./script.sh : line 52 : 1372757584 : not found

After some changes suggested from the comments:

Ok the error now is below:

scone.sh: line 46: ((: 1372768246 -gt 1372770593 - 3600*24*30 : syntax error
in expression (error token is "1372770593 - 3600*24*30 ")
  • 4
    Please run it as bash -vx ./script.sh. Are the bash versions on the two platforms different? You may use if [ "$tempval" -gt $(($(date +%s) - 3600*24*30)) ] instead. – Hauke Laging Jul 2 '13 at 11:31
  • 2
    Is it being run in bash in both instances? And/or could there be a runaway construct which starts somewhere in lines 1-40 which ends at line 52 and expands to the number you see? – tripleee Jul 2 '13 at 11:47
  • Ok i've actually done both what you suggested. I run on bash and replaced > sign with -gt expression,and now i am getting the error above.See first post for the new error. – Vaios Argiropoulos Jul 2 '13 at 13:20
  • 1
    -gt only works with [ and [[. – user26112 Jul 2 '13 at 14:22
  • 2
    If you have found a solution to your problem, post it as an answer to this question and accept it. – user26112 Jul 2 '13 at 16:12

I've actually made the changes suggested by the 3 guys at the comments and all of them were necessary for the script to work.

Final code below:

temptime=$(date +%s)
temptime=`expr $temptime - 2592000`

for DIR in $DIRS
echo $tempdir
tempval=$(stat -c %Y $tempdir)
echo $tempval
if [[ $tempval -gt $temptime ]]; then
    echo "Exiting gracefully!!!"
  • 1
    These backticks are hard to read on the screen. You could consider using things like $(expr $temptime - 2592000) instead. – ott-- Jul 2 '13 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.