Backstory, I run emacs native comp branch from ArchlinuxCN and it updates a lot, sometimes twice a day or more, which leads to the elncache being rebuilt after every update. So I thought I would only update once a week and wrote this, but it is failing:
DAY=$(date +"%u")
echo ">>>>>>>>>"$DAY
if [ "$DAY" == "2" ]; then #fails here ***********************
echo "Equal"
sudo sed -i 's/#IgnorePkg = emacs-native-comp-git/IgnorePkg = emacs-native-comp-git/' /etc/pacman.conf
else
echo "Not Equal"
sudo sed -i 's/IgnorePkg = emacs-native-comp-git/#IgnorePkg = emacs-native-comp-git/' /etc/pacman.conf
fi
This is just the bit that goes wrong, I know the sed commands work OK, so it is my logic???
case "$(date +%a)" in
Tue)
sudo sed -i 's/#IgnorePkg = emacs-native-comp-git/IgnorePkg = emacs-native-comp-git/g' /etc/pacman.conf
break
;;
*)
sudo sed -i 's/IgnorePkg = emacs-native-comp-git/#IgnorePkg = emacs-native-comp-git/g' /etc/pacman.conf
;;
esac
Can you check in /etc/pacman.conf if the spacing matches like in this? #IgnorePkg = emacs-native-comp-git (note that there is only 1 space after IgnorePkg then another space, in the default pacman.conf there are a 2/3 spaces after #IgnorePkg so sed will not write/change it because of that)
syu
╔══════════════════╗
║ Updating Mirrors ║
╚══════════════════╝
╔════════════════════════════════════╗
║ Finding fastest Arch mirror....... ║
╚════════════════════════════════════╝
╔══════════════════════════════════════════╗
║ Mirrors have already been updated today! ║
╚══════════════════════════════════════════╝
:: Synchronizing package databases...
kde-unstable is up to date
gnome-unstable is up to date
core is up to date
extra is up to date
community 5.6 MiB 1741 KiB/s 00:03 [-------------------------------------------------------] 100%
multilib is up to date
endeavouros is up to date
archlinuxcn is up to date
chaotic-aur 1373.9 KiB 678 KiB/s 00:02 [-------------------------------------------------------] 100%
liquorix is up to date
jk-aur is up to date
herecura is up to date
>>>>>>>>>2
/home/xircon/scripts/syu.sh:56: = not found
I am using zsh because of the very handy fork and disown - &!
It shouldn’t in bash. That is why I was asking about your shell.
In general, there are a lot of differences between zsh and bash. They are have different extensions to POSIX. If you want something to work in either shell, just make is POSIX compliant.
Alternatively, even if you use zsh, that script could be executed in bash.
I try to do all my scripting in bash even though I use zsh.