Home > Back-end >  Conditional `if` statement with strings in shell script to configure two computers differently (Ubun
Conditional `if` statement with strings in shell script to configure two computers differently (Ubun

Time:10-18

I want to check the current distro in .profile because I have two computers. In one I have Ubuntu with Gnome, and in another I have Debian with XFCE. In either case I want to have different configurations, but I can't manage to even get the following code working in Ubuntu:


if [[ awk '{gsub(/ /, "", $1); print $1=$1}' /etc/issue == "Ubuntu" ]]; then
            gsettings set org.gnome.mutter overlay-key ''
            gsettings set org.gnome.shell.extensions.dash-to-dock hot-keys false
fi

I get:


bash: .bashrc:223: conditional binary operator expected
bash: .bashrc:223: syntax error near `$1=$1}''
bash: .bashrc:223: `if [[ awk '{gsub(/ /, "", $1); print $1=$1}' /etc/issue == "Ubuntu" ]]; then'

But as far as I can tell, the conditional is rightly specified... Any clues any one?

CodePudding user response:

I suggest to replace

if [[ awk '{gsub(/ /, "", $1); print $1=$1}' /etc/issue == "Ubuntu" ]]; then

with

source /etc/os-release
if [[ "$NAME" == "Ubuntu" ]]; then
  • Related