I'm modifying my .bash_profile file so that when I run ipy it clears the log file every seven or more days. The problem is when ever I reference a variable within my if statement I get back -bash: command not found.
1 #!/bin/sh
2 # .bash_profile
...
15 # These lines clear the ipy.log every seven or more days
16 PREV=$(awk '/./{line=$0} END{print line}' days.log)
17 echo $PREV
18 WEEKDAY=$(date '+%Y%m%d')
19 echo $WEEKDAY
20 DIF=$((WEEKDAY-PREV))
21 MARKER=false
22 if [ ${DIF} > 6 ]; then
23 YEAR=$(date '+%Y')
24 MON=$(date '+%m')
25 DAY=$(date '+%d')
26 DIGIT=${DAY:-1}
27 if [ ${DIGIT} -eq 1 ]; then
28 TAG='st'
29 elif [ ${DIGIT} -eq 2 ]; then
30 TAG='nd'
31 elif [ ${DIGIT} -eq 3 ]; then
32 TAG='rd'
33 else
34 TAG='th'
35 fi
36 TIMESTAMP=$(date '+%H:%M:%S')
37 MARKER=true
38 PRINT=$("ipy.log was cleared at ${TIMESTAMP} on ${WEEKDAY} the ${DAY}${TAG} of ${MON}, ${YEAR}")
39 echo ${PRINT}
40 ${PRINT} > ~/ipy.log
41 ${WEEKDAY} > ~/days.log
42 else
43 echo "It has been ${DIF} days since your last write, no need to clear logs"
44 fi
OUTPUT:
20200216
-bash: ipy.log was cleared at 14:35:45 on 20200216 the 16th of 02, 2020: command not found
-bash: 20200216: command not found
You'll notice that when I call upon the last line of my days.log file and assign it to the variable $PREV it only gets null assigned to it, however this is a problem that I'll formally ask in another post. I would like to figure out how and why the command not found statements are being raised.