The if statement doesn’t seem to be functioning correctly, no matter the if statement result, the program launches. What have I missed?
#!/bin/bash
dtime=($(date |cut -c12-13))
sevenO="19"
redshift=($(gtk-redshift -l -31.9530044:115.8574693))
if ( [[ "$dtime" -gt "$sevenO" ]])
then
$redshift
fi
Do I understand correctly that you only want to run
gtk-redshiftif the time is between 8 PM and midnight? If so, the problem is that this notation:runs the command
...immediately, and evaluates to its output; so this statement:runs the command
gtk-redshift -l -31.9530044:115.8574693, and then sets the variableredshiftto be an array containing the output of that command. (An array because of the surrounding(...). Note that in Bash, parentheses are not used for mere grouping. They have actual behaviors — such as, in this case, creating an array — and you shouldn’t use them in places where you don’t want those behaviors.)You can simplify your Bash script to just this: