I want to check current GTK theme and want to check current time, and based on that would like to change the theme as follows:
GtkTheme=$(/usr/bin/gsettings get org.gnome.desktop.interface gtk-theme)
NightTheme="Adapta-Nokto"
DayTheme="Adapta"
TimeHrWithZero=$(date +%H)
TimeHr=$(bc<<<${TimeHrWithZero})
if [ "${GtkTheme}" != "${NightTheme}" ] && if ((${TimeHr}>=19 || ${TimeHr}<=5)); then
echo ${GtkTheme} ${TimeHr} Night Theme
/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme ${NightTheme}
else
echo ${GtkTheme} ${TimeHr} Day Theme
/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme "${DayTheme}"
fi
When I remove if [ "${GtkTheme}" != "${NightTheme}" ] && the code works but without that condition. How can I compare with both string and integer comparison together?
date +%_H(with the underscore) -- hours "08", "09" will result in arithmetic errors due to bash interpreting numbers with leading 0 as octal, and 8 and 9 are invalid octal digits:bash: ((: 09: value too great for base (error token is "09")-- the date format%_Huses a space to pad the hour instead of a zero.TimeHr=$(bc<<<${TimeHrWithZero})to solve that issue.TimeHr=$(date +%_H). You could also use parameter expansion to remove a leading zero:TimeHr=$(date +%H); TimeHr=${TimeHr#0}