-Eq: Unary Operator Expected [Duplicate]

-Eq: Unary Operator Expected [Duplicate]

I have this script, which changes NVIDIA-SETTINGS vibrance, when certain application/process is launched (in my case Counter-Strike:Global Offensive game)

Script:

#!/bin/bash

on="1023"
off="0"
dv="0"


# RESET
sleep 10
log "RESET"
nvidia-settings -a "[gpu:0]/DigitalVibrance[DFP-0]=$off"

while true; do #daemon mode
dv=`nvidia-settings -q "[gpu:0]/DigitalVibrance[DFP-0]" -t`
  if pgrep -l csgo | grep csgo_linux
  then
#  log "Process csgo_linux found"
    if [ $dv -eq $off ]; then
      nvidia-settings -a "[gpu:0]/DigitalVibrance[DFP-0]=$on"
    fi
  else
# No process found
    if [ $dv -eq $on ]; then
      nvidia-settings -a "[gpu:0]/DigitalVibrance[DFP-0]=$off"
    fi
  fi

  if [ $dv -eq $on ]; then
  sleep 5
  else
  sleep 1
  fi

done

What is wrong with this script, why it gives me these errors?

622 csgo_linux64
/home/matas/Desktop/vib-gui.sh: line 18: [: -eq: unary operator expected
/home/matas/Desktop/vib-gui.sh: line 28: [: -eq: unary operator expected
622 csgo_linux64
/home/matas/Desktop/vib-gui.sh: line 18: [: -eq: unary operator expected
/home/matas/Desktop/vib-gui.sh: line 28: [: -eq: unary operator expected
622 csgo_linux64
/home/matas/Desktop/vib-gui.sh: line 18: [: -eq: unary operator expected
/home/matas/Desktop/vib-gui.sh: line 28: [: -eq: unary operator expected
622 csgo_linux64
/home/matas/Desktop/vib-gui.sh: line 18: [: -eq: unary operator expected
/home/matas/Desktop/vib-gui.sh: line 28: [: -eq: unary operator expected

EDIT:

#!/bin/bash

on="1023"
off="0"
dv="0"


# RESET
sleep 10
nvidia-settings -a "[gpu:0]/DigitalVibrance[DFP-0]=$off"

while true; do #daemon mode
dv=`nvidia-settings -q "[gpu:0]/DigitalVibrance[DFP-0]" -t`
  if pgrep -l csgo | grep csgo_linux
  then
#  log "Process csgo_linux found"
    if [ "$dv -eq $off" ]; then
      nvidia-settings -a "[gpu:0]/DigitalVibrance[DFP-0]=$on"
    fi
  else
# No process found
    if [ "$dv" -eq "$on" ]; then
      nvidia-settings -a "[gpu:0]/DigitalVibrance[DFP-0]=$off"
    fi
  fi

  if [ "$dv -eq $on" ]; then
  sleep 5
  else
  sleep 1
  fi

done
14

2 Answers

To fix this specific problem

There are other issues with your script presumably dealt with in Byte Commander's answer, but for those coming in from Google, to fix this specific problem, always surround variables with double quotes. For example [ "$dv" -eq "$on" ].

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.