I have this simple bash script called get-volume.sh:
mutedStatus=`amixer -c 0 -D pulse get Master | tail -n 1 | grep -c '\[on\]'`
echo $mutedStatus
if "$mutedStatus" -eq 0; then
echo 'x'
else
echo `amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1`
fi
exit 0
It should
- populate the
mutedStatusvariable with 1 if unmuted and 0 if muted - if muted, echo 'x', else echo the volume
- exit
But when I run the script with bash get-volume.sh I get this irritating message:
1
get-volume.sh: line 7: 1: command not found
100
why is it giving that error?
It seems to be trying to execute my variable, which is where 1: comes from, as when I mute my system the message changes to
get-volume.sh: line 7: 0: command not found
-eqis not a shell operator; it's an argument to be interpreted by thetestcommand. You are literally trying to run a command named1with arguments-eqand0.ifstatement is a command, not an expression. The condition is true if the command succeeds, false if it fails.[is a special (often built-in) command that evaluates an expression.#!.bin/bashshould be:#!/bin/bash