I am trying to pipe information from my workspaces into another command, and because each workspace contains the same information, with only a different number to identify it, I have written 10 functions where the only difference is one character inside some variable names. I feel like this can be greatly simplified, but I cannot figure out how to get any sort of loop working in my situation.
All here is my script containing the 10 functions:
#!/bin/bash
# Include config file.
. $(dirname $0)/config
getWorkspaceInfo(){
filledWorkspaces=$(i3-msg -t get_workspaces | grep -Po '"'"name"'"\s*:\s*"\K([^"]*)')
currentWorkspace=$(i3-msg -t get_outputs | sed 's/.*"current_workspace":"\([^"]*\)".*/\1/')
}
# Determine the status of each workspace. Current is green, unfocused is white, empty is grey.
workspace1(){
if [[ ${currentWorkspace} -eq 1 ]]; then
workspace1Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "1") == "" ]]; then
workspace1Color=${grey}
else
workspace1Color=${foreground}
fi
echo "%{F${workspace1Color}}${workspace1Name}"
}
workspace2(){
if [[ ${currentWorkspace} -eq 2 ]]; then
workspace2Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "2") == "" ]]; then
workspace2Color=${grey}
else
workspace2Color=${foreground}
fi
echo "%{F${workspace2Color}}${workspace2Name}"
}
workspace3(){
if [[ ${currentWorkspace} -eq 3 ]]; then
workspace3Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "3") == "" ]]; then
workspace3Color=${grey}
else
workspace3Color=${foreground}
fi
echo "%{F${workspace3Color}}${workspace3Name}"
}
workspace4(){
if [[ ${currentWorkspace} -eq 4 ]]; then
workspace4Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "4") == "" ]]; then
workspace4Color=${grey}
else
workspace4Color=${foreground}
fi
echo "%{F${workspace4Color}}${workspace4Name}"
}
workspace5(){
if [[ ${currentWorkspace} -eq 5 ]]; then
workspace5Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "5") == "" ]]; then
workspace5Color=${grey}
else
workspace5Color=${foreground}
fi
echo "%{F${workspace5Color}}${workspace5Name}"
}
workspace6(){
if [[ ${currentWorkspace} -eq 6 ]]; then
workspace6Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "6") == "" ]]; then
workspace6Color=${grey}
else
workspace6Color=${foreground}
fi
echo "%{F${workspace6Color}}${workspace6Name}"
}
workspace7(){
if [[ ${currentWorkspace} -eq 7 ]]; then
workspace7Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "7") == "" ]]; then
workspace7Color=${grey}
else
workspace7Color=${foreground}
fi
echo "%{F${workspace7Color}}${workspace7Name}"
}
workspace8(){
if [[ ${currentWorkspace} -eq 8 ]]; then
workspace8Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "8") == "" ]]; then
workspace8Color=${grey}
else
workspace8Color=${foreground}
fi
echo "%{F${workspace8Color}}${workspace8Name}"
}
workspace9(){
if [[ ${currentWorkspace} -eq 9 ]]; then
workspace9Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "9") == "" ]]; then
workspace9Color=${grey}
else
workspace9Color=${foreground}
fi
echo "%{F${workspace9Color}}${workspace9Name}"
}
workspace10(){
if [[ ${currentWorkspace} -eq 10 ]]; then
workspace10Color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "10") == "" ]]; then
workspace10Color=${grey}
else
workspace10Color=${foreground}
fi
echo "%{F${workspace10Color}}${workspace10Name}"
}
# Pipe functions to the bar infinitely.
while true; do
getWorkspaceInfo
echo "%{c}$(workspace1)${separator}$(workspace2)${separator}$(workspace3)${separator}$(workspace4)${separator}$(workspace5)${separator}$(workspace6)${separator}$(workspace7)${separator}$(workspace8)${separator}$(workspace9)${separator}$(workspace10)"
done | lemonbar -g ${panelWidth}x${panelHeight}+${panelX}+${bottomPanelY} -f "${font}" -f "${iconFont}" -B "${background}" -F "${foreground}" -p -d | \
while true; do read line; eval $line; done &
Here is the config file that I am importing:
#!/bin/bash
# Outside sources
xres="$HOME/.Xresources"
i3config="$HOME/.config/i3/config"
# Fetch information from Xresources
background=$(cat ${xres} | grep -i background | tail -c 8)
foreground=$(cat ${xres} | grep -i foreground | tail -c 8)
black=$(cat ${xres} | grep -i color0 | tail -c 8)
grey=$(cat ${xres} | grep -i color8 | tail -c 8)
red=$(cat ${xres} | grep -i color9 | tail -c 8)
green=$(cat ${xres} | grep -i color10 | tail -c 8)
yellow=$(cat ${xres} | grep -i color11 | tail -c 8)
blue=$(cat ${xres} | grep -i color12 | tail -c 8)
magenta=$(cat ${xres} | grep -i color13 | tail -c 8)
cyan=$(cat ${xres} | grep -i color14 | tail -c 8)
white=$(cat ${xres} | grep -i color15 | tail -c 8)
# Fetch information from i3 config
gapSize=$(cat ${i3config} | grep -i "gaps inner" | awk '{print $3}')
# Workspace names -- independant from i3 config -- workspaces in i3 config should be named numbers 1-10.
workspace1Name="Web Browser"
workspace2Name="Terminal"
workspace3Name="Text Editor"
workspace4Name="Unspecified"
workspace5Name="Unspecified"
workspace6Name="Unspecified"
workspace7Name="Unspecified"
workspace8Name="Unspecified"
workspace9Name="Messenger"
workspace10Name="Music Player"
# Fonts
font="InputSans-10"
iconFont="FontAwesome"
separator="%{F$foreground} |│| "
# Panel size
screenWidth=$(xrandr | grep 'Screen 0'| awk '{print $8}')
screenHeight=$(xrandr | grep 'Screen 0' | awk '{print $10}' | tr -d ",")
panelHeight=$((${gapSize} * 2))
panelWidth=$((${screenWidth} - ${panelHeight}))
panelX=${gapSize}
topPanelY=${gapSize}
bottomPanelY=$((${screenHeight} - ${panelHeight} - ${gapSize}))
Well, the simplest fix is to write something like:
function all_10_workspaces () {
local i
for i in {1..10} ; do
local workspaceNameVar="workspace${i}Name"
local workspaceName="${!workspaceNameVar}"
local color
if (( currentWorkspace == 1 )) ; then
color=$green
elif grep -w -q "$i" <<< "$filledWorkspaces" ; then
color=$foreground
else
color=$grey
fi
echo "%{F$color}$workspaceName"
done
}
. . . however, you should really consider using arrays instead. For example:
workspaceNames=(
'' # 0 (no such workspace)
'Web Browser' # 1
Terminal # 2
'Text Editor' # 3
Unspecified # 4
Unspecified # 5
Unspecified # 6
Unspecified # 7
Unspecified # 8
Messenger # 9
'Music Player' # 10
)
Then, for example, workspace #7 is named "${workspaceNames[7]}", and given a variable i, workspace #i is named "${workspaceNames[i]}".
Something like this, perhaps?
workspaceCount=10
while true; do
# Output will look like "%{c}$(workspace1Color)${separator}$(workspace2Color)${separator}...."
# This is what is sent before the first item in each line
itemSep="%{c}"
for i in {1..$workspaceCount}; do
if [ ${currentWorkspace} -eq $i ]; then
color="${green}"
elif [[ $(echo ${filledWorkspaces} | grep -w "1") == "" ]]; then
color="${grey}"
else
color="${foreground}"
fi
echo -n "${itemSep}${color}"
itemSep="${separator}"
done
echo # Send LF after all items
done
I figured out a way to get what I wanted using ideas from both ruakh and Phil Freed as well as something I came up with on my own. This may not be the shortest or most efficient way to solve the problem, but it is much shorter than having 10 separate functions.
#!/bin/bash
# Include config file.
. $(dirname $0)/config
getWorkspaceInfo(){
filledWorkspaces=$(i3-msg -t get_workspaces | grep -Po '"'"name"'"\s*:\s*"\K([^"]*)')
currentWorkspace=$(i3-msg -t get_outputs | sed 's/.*"current_workspace":"\([^"]*\)".*/\1/')
}
# Determine the status of each workspace. Current is green, unfocused is white, empty is grey.
workspaces(){
workspaces=""
currentSeparator="${separator}"
for i in {1..10} ; do
if [[ ${currentWorkspace} -eq ${i} ]]; then
color=${green}
elif [[ $(echo ${filledWorkspaces} | grep -w "${i}") == "" ]]; then
color=${grey}
else
color=${foreground}
fi
if [[ ${i} -eq 10 ]]; then
currentSeparator=""
fi
workspaces+="%{F$color}${workspaceNames[i]}${currentSeparator}"
done
echo "${workspaces}"
}
# Pipe functions to the bar infinitely.
while true; do
getWorkspaceInfo
echo "%{c}$(workspaces)"
done | lemonbar -g ${panelWidth}x${panelHeight}+${panelX}+${bottomPanelY} -f "${font}" -f "${iconFont}" -B "${background}" -F "${foreground}" -p -d | \
while true; do read line; eval $line; done &
To explain what it does as simply as possible:
Loop through all 10 workspaces, adding what would have been the output of a single function to the end of a new variable. Since I cannot add a separator between each function call anymore, I simply added the separator to the end of the echo, making sure that no separator is added to the last workspace by using a for loop, which sets the separator variable to null.
Related
I'm an trying to add a toggle to a script that contains a loop. The toggle would be a mouse button press that would start the loop or start the loop at will. The only way I have been able to make the toggle work correctly was to separate the toggle and action scripts. When I attempt to join the 2, when the toggle button is hit, it does not break out of the inner loop correctly.
Toggle Script
#!/bin/bash
PIDS=`pidof -o $$ -x $0`
if [ x$PIDS != x ]
then
exit 0
fi
echo -e "\nToggle:"
TOGGLE=$HOME/.toggle
if [ ! -e $TOGGLE ]; then
touch $TOGGLE
fi
echo "${TOGGLE}"
echo -e "\nMouse:"
if [[ $(xinput --list | grep "My Mouse Label 1") == *Mouse* ]]; then
pointerLabel="My Mouse Label 1"
else
pointerLabel="My Mouse Label 2"
fi
pointerDevice=`xinput --list --id-only "${pointerLabel}" `
echo "${pointerLabel}"
echo -e "\nKeyboard:"
keyboardLabel="My Keyboard Label"
echo "${keyboardLabel}"
keyboardDevice=`xinput --list --id-only "${keyboardLabel}" `
scan_id=1
while [ true ]
do
state_mouse="$(xinput --query-state "${pointerDevice}")"
if [[ "${state_mouse}" == *"button[8]=down"* ]]; then
if [ -f ${TOGGLE} ]; then
rm -f ${TOGGLE}
echo "Toggle Off"
sleep .5s
else touch ${TOGGLE}
echo "Toggle On"
sleep .5s
fi
fi
scan_id=`expr ${scan_id} + 1 `
done
Action Script
#!/bin/bash
PIDS=`pidof -o $$ -x $0`
if [ x$PIDS != x ]
then
exit 0
fi
TOGGLE=$HOME/.toggle
action(){
sub_id=1
while [[ -f ${TOGGLE} ]]
do
state="$(xinput --query-state "${keyboardDevice}" | grep 'down' )"
if [ -n "${state}" ]
then
if [[ "${state}" == *"key[10]=down"* ]]; then
xdotool key --clearmodifiers 1
elif [[ "$state" == *"key[11]=down"* ]]; then
xdotool key --clearmodifiers 2
elif [[ "$state" == *"key[12]=down"* ]]; then
xdotool key --clearmodifiers 3
fi
break
fi
sub_id=`expr ${sub_id} + 1 `
sleep 1
done
}
echo -e "\nToggle:"
echo "${TOGGLE}"
echo -e "\nMouse:"
if [[ $(xinput --list | grep "My Mouse Label 1") == *Mouse* ]]; then
pointerLabel="My Mouse Label 1"
else
pointerLabel="My Mouse Label 2"
fi
pointerDevice=`xinput --list --id-only "${pointerLabel}" `
echo "${pointerLabel}"
echo -e "\nKeyboard:"
keyboardLabel="My Keyboard"
echo "${keyboardLabel}"
keyboardDevice=`xinput --list --id-only "${keyboardLabel}" `
scan_id=1
while [ true ]
do
action
scan_id=`expr ${scan_id} + 1 `
done
I've tried to reproduce the logic of your script (with adaptations for my own desktop), in order to understand what you are doing.
The following script has moved your inner "while" logic as an external function, in order to clean up visibility of what is happening (for myself).
I have also slightly modified the logic within the inner while, so that a break can be triggered by any of the matched conditions. I believe this is what you were looking for, in order to abandon the inner loop upon match of the second condition.
If I am wrong, please clarify your needs and I will rework the logic and code. Please not that there are many statements that have been added in order to provide meaningful diagnostics of results at various stages in order to understand what needs to be "handled".
#!/bin/bash
PIDS=`pidof -o $$ -x $0`
if [ x$PIDS != x ]
then
exit 0
fi
action(){
sub_id=1
while [[ ${toggle_status} -eq 1 ]]
do
#state="$(xinput --query-state "${keyboardDevice}")"
#echo -e "\n[${scan_id}/${sub_id}] state = ${state} ..." | awk '{ printf("\t\t Inner |%s\n", $0 ) ; }'
state="$(xinput --query-state "${keyboardDevice}" | grep 'down' )"
#if [[ "${state}" == *"key[10]=down"* ]]; then
if [ -n "${state}" ]
then
if [[ "${state}" == *"key[10]=down"* ]]; then
### keypress = top row "1"
echo -e "\n[${scan_id}/${sub_id}] state = ${state} ..." | grep 'down' | awk '{ printf("\n\t\t Inner_2 |%s\n", $0 ) ; }'
echo "\t toggle= ${toggle}"
elif [[ "$state" == *"key[11]=down"* ]]; then
### keypress = top row "2"
echo -e "\n[${scan_id}/${sub_id}] state = ${state} ..." | grep 'down' | awk '{ printf("\n\t\t Inner_2 |%s\n", $0 ) ; }'
xdotool key --clearmodifiers 2
elif [[ "$state" == *"key[12]=down"* ]]; then
### keypress = top row "3"
echo -e "\n[${scan_id}/${sub_id}] state = ${state} ..." | grep 'down' | awk '{ printf("\n\t\t Inner_2 |%s\n", $0 ) ; }'
xdotool key --clearmodifiers 3
fi
break ### exit inner loop if condition matched
fi
sub_id=`expr ${sub_id} + 1 `
sleep 1
done
}
echo -e "\nReport of all X devices:"
xinput --list
echo ""
echo -e "\nObtain label for mouse device:"
pointerLabel=`xinput --list --name-only | grep '[Mm][Oo][Uu][Ss][Ee]' `
echo "pointerLabel = ${pointerLabel}"
echo -e "\nObtain X device for mouse:"
pointerDevice=`xinput --list --id-only "${pointerLabel}" `
echo "pointerDevice = ${pointerDevice}"
echo -e "\nObtain label for keyboard device:"
#keyboardLabel=`xinput --list --name-only | grep '[Kk][Ee][Yy][Bb][Oo][Aa][Rr][Dd]' `
keyboardLabel=`xinput --list --name-only | grep 'dakai' | grep -v 'Control' `
echo "keyboardLabel = ${keyboardLabel}"
echo -e "\nObtain X device for mouse:"
keyboardDevice=`xinput --list --id-only "${keyboardLabel}" `
echo "keyboardDevice = ${keyboardDevice}"
toggle=1 ### initial value should normally be 0, i.e. un-set
scan_id=1
while [ true ]
do
state2="$(xinput --query-state "${pointerDevice}")"
#state2="$(xinput --query-state "${pointerDevice}" | grep 'button\[8\]=down' )"
#state2="$(xinput --query-state "${pointerDevice}" | grep 'button\[1\]=down' )"
echo -e "\n[${scan_id}] state2 = ${state2} ..." | awk '{ printf("\t Outer |%s\n", $0 ) ; }'
#if [ -n "${state2}" ]
#if [[ "${state2}" == *"button[8]=down"* ]]
if [[ "${state2}" == *"button[1]=down"* ]]
then
if [ ${toggle} -eq 1 ]
then
toggle_status=0
else
toggle_status=1
fi
echo ${toggle_status}
toggle=${toggle_status}
sleep .5s
fi
action
echo "sleeping 2 sec ..." ; sleep 2
scan_id=`expr ${scan_id} + 1 `
done
I trying to make script that shows volume level of active volume sink. Here is code
#!/bin/bash
active_sink=$(pacmd list-sinks |awk '/* index:/{print $3}')
muted=$(pactl list sinks | perl -000ne 'if(/#${active_sink}/){/(Mute:.*)/; print "$1\n"}' | cut -f2 -d':' | cut -f2 -d' ')
vol=$(pactl list sinks | perl -000ne 'if(/#${active_sink}/){/(Volume:.*)/; print "$1\n"}' | cut -f1 -d'%' | tail -c 3
)
if [[ $muted = "no" ]]; then
if [[ $vol -ge 65 ]]; then
echo ~/.config/tint2/executors/icons/audio-volume-high.svg
echo "$vol%"
elif [[ $vol -ge 40 ]]; then
echo ~/.config/tint2/executors/icons/audio-volume-medium.svg
echo "$vol%"
elif
[[ $vol -ge 0 ]]; then
echo ~/.config/tint2/executors/icons/audio-volume-low.svg
echo "$vol%"
fi
else
echo ~/.config/tint2/executors/icons/audio-volume-muted.svg
echo "muted"
fi
I can't get this script to work, always get "muted".
I finally makes this thing to work, thanks #markp-fuso.
The problem was with perl and ${active_sink}.
Final code that work with corrected muted and vol
#!/bin/bash
active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}')
muted=$(pactl list sinks | grep -A14 -P "(\#|№)$active_sink" | awk '/Mute:/{print $2}')
vol=$(pactl list sinks | grep -A14 -P "(\#|№)$active_sink" | awk '/Volume: front-left:/{print $5}' | cut -f1 -d'%')
if [[ $muted = "no" ]]; then
if [[ $vol -ge 65 ]]; then
echo ~/.config/tint2/executors/icons/audio-volume-high.svg
echo "$vol%"
elif [[ $vol -ge 40 ]]; then
echo ~/.config/tint2/executors/icons/audio-volume-medium.svg
echo "$vol%"
elif
[[ $vol -ge 0 ]]; then
echo ~/.config/tint2/executors/icons/audio-volume-low.svg
echo "$vol%"
fi
else
echo ~/.config/tint2/executors/icons/audio-volume-muted.svg
echo "muted"
fi
So I have this BASH script and what i want to do is, reach out to the servers. Check the used % of a directory. If it is higher than my set threshold (90) then print that server name to another file on the server where the script has been run from.
What it is doing is printing the first server name twice in to the file so it looks like
server1
server2
Here is my script ... I don't see why it would be going around in a loop to that first server twice
#!/bin/bash
SERVERS="server1
server2"
for i in $SERVERS; do
ssh $SERVERS "
df -h | grep var | awk '{print \$4}' | sed 's/%//g' > /home/user/space.txt
RESULTS=\$(grep -E "1[5-9]" /home/user/space.txt)
THRESHOLD=90
if [[ \$RESULTS -lt \$THRESHOLD ]]; then
exit 1;
elif [[ \$RESULTS -gt \$THRESHOLD ]]; then
hostname;
fi
" >> /home/user/problem.txt
done
Try this,
#!/bin/bash
SERVERS="server1
server2"
for i in $SERVERS; do
ssh "$i" "
df -h | grep var | awk '{print \$4}' | sed 's/%//g' > /home/user/space.txt
RESULTS=\$(grep -E "1[5-9]" /home/user/space.txt)
THRESHOLD=90
if [[ \$RESULTS -lt \$THRESHOLD ]]; then
exit 1;
elif [[ \$RESULTS -gt \$THRESHOLD ]]; then
hostname;
fi
" >> /home/user/problem.txt
done
I wrote the following script:
#!/bin/bash
echo "Reading data - headers - both"
if [ $# -ne 3 ]; then
echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
exit 1
fi
rm -f /tmp/right.txt 1>/dev/null 2>/dev/null
rm -f /tmp/wrong.txt 1>/dev/null 2>/dev/null
output=""
if [ $3 == h ]; then
while read -r -u3 port; do
while read -r -u4 ip; do
# echo -en "\n$ip $port: "
OUT=$( nmap -p "$port" --script=http-headers.nse "$ip" | awk 'NR>=7 && NR<=10')
# [[ $OUT == *Apache* ]] && $(echo -en "$ip $port\n" >> /tmp/right.txt) || $(echo -en "$ip $port\n" >> /tmp/wrong.txt)
[[ $OUT == *Apache* ]] && output="$output `echo -en "\n$ip -------------------- $port "`" && echo -e "$output" | column -t >> /tmp/right.txt || output="$output `echo -en "\n$ip -------------------- $port "`" && echo -e "$output" | column -t >> /tmp/wrong.txt
done 4< "$2"
done 3< "$1"
echo -e "$output" | column -t
elif [ $3 == d ]; then
echo data
elif [ $3 == b ]; then
echo both
fi
I expect my output have two files:
cat right.txt
ip1 ..... port1
ip2 ..... port1
ip2 ..... port2
ip3 ..... port3
.
.
.
cat wrong.txt
ip1 ..... port1
ip2 ..... port1
ip2 ..... port2
ip3 ..... port3
.
.
.
but it doesn't work properly...
any idea?
Thank you in advance
please find updated answer as i modified the BMW's answer for you please check it.
#!/bin/bash
echo "Reading data - headers - both"
if [ $# -ne 3 ]; then
echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
exit 1
fi
join -j 2 $2 $1 > temp.txt
headers()
{
while read -r ip port
do
printf "ip: %s port:%d \n" $ip $port
OUT=$(nmap -p "$port" --script=http-headers.nse "$ip" | tac | awk -F: 'NR<=13&&/Apache/{print $2; exit}')
if [[ "$OUT" == *Apache* ]]; then
echo $ip $port >> /tmp/right.txt
else
echo $ip $port >> /tmp/wrong.txt
fi
done < temp.txt
}
case $3 in
"h") headers ;;
"d") echo data;;
"b") echo both;;
"*") echo "wrong input"
exit;;
esac
Your short-circuit logic is flawed. true && false || true && true will execute all four statements.
It's not clear why you think the output status of echo would indicate anything except success anyway.
Is this closer to what you mean?
output="$output `echo -en "\n$ip -------------------- $port "`"
[[ $OUT == *Apache* ]] && file=/tmp/right.txt || file=/tmp/wrong.txt
echo -e "$output" | column -t >>"$file"
This is still wrong because it will echo the accumulated output multiple times, but at least it should show you what needs to be changed (and also how to refactor your code to avoid repetitions).
I guess you actually want something like
[[ $OUT == *Apache* ]] && file=/tmp/right.txt || file=/tmp/wrong.txt
output="$output `echo -en "\n$ip -------------------- $port " | tee -a "$file"`"
except this doesn't run the copy in the file through column -t. But you can do that later, or add it here and avoid it later (you seem to be running it for all instances of the output in the end anyway).
I am trying to use whether or not a line contains a date as a condition for an if statement:
if [grep -n -v '[0-9][0-9][0-9][0-9]' $line |wc -l==0]
then
...
The above returns an error. I don't necessarily need to use grep. The line processed by grep would look like:
1984 Dan Marino QB Miami Dolphins
Any help is appreciated.
if [[ $(echo $line | grep -q '[0-9][0-9][0-9][0-9]') ]]; then
# do something
fi
You can check this using bash built-ins:
re='\b[[:digit:]]{4}\b'
if [[ $line =~ $re ]] ; then
echo ok;
fi
[grep -n -v '[0-9][0-9][0-9][0-9]' $line |wc -l==0]
problem 1: [(space).....(space)] you need those spaces
problem 2: there is no [ foo==bar ] you can do something like [ $(echo "0") = "0" ] or [[ $(echo "0") == 0 ]] here the $(echo "0") is an example, you should fill with your commands.
You can just call grep with -q option and check the return value:
if [ $(grep -qv '[0-9][0-9][0-9][0-9]' $line) -eq 0 ]; then
# ...
fi
Use command substitution and proper bash syntax.
[[ "`grep -n -v '[0-9][0-9][0-9][0-9]' $line | wc -l`" -eq 0 ]]