grep - What do ^$ and ^# mean? - Ask Ubuntu


i don't understand badips=$(egrep -v "^#|^$" $tdb). can explain it? full code:

#!/bin/bash # purpose: block traffic afghanistan (af) , china (cn). use iso code. # # see url more info - http://www.cyberciti.biz/faq/?p=3402 # author: nixcraft <www.cyberciti.biz> under gpl v.2.0+ # ------------------------------------------------------------------------------- iso="af cn"   ### set path ### ipt=/sbin/iptables wget=/usr/bin/wget egrep=/bin/egrep  ### no editing below ### spamlist="countrydrop" zoneroot="/root/iptables" dlroot="http://www.ipdeny.com/ipblocks/data/countries"  cleanoldrules(){ $ipt -f $ipt -x $ipt -t nat -f $ipt -t nat -x $ipt -t mangle -f $ipt -t mangle -x $ipt -p input accept $ipt -p output accept $ipt -p forward accept }  # create dir [ ! -d $zoneroot ] && /bin/mkdir -p $zoneroot  # clean old rules cleanoldrules  # create new iptables list $ipt -n $spamlist  c  in $iso      # local zone file     tdb=$zoneroot/$c.zone      # fresh zone file     $wget -o $tdb $dlroot/$c.zone      # country specific log message     spamdropmsg="$c country drop"      #      badips=$(egrep -v "^#|^$" $tdb)     ipblock in $badips            $ipt -a $spamlist -s $ipblock -j log --log-prefix "$spamdropmsg"        $ipt -a $spamlist -s $ipblock -j drop     done done  # drop  $ipt -i input -j $spamlist $ipt -i output -j $spamlist $ipt -i forward -j $spamlist  # call other iptable script # /path/to/other/iptables.sh  exit 0 

^ regular expression special character used mark start of line, , $ marks end of line. they're used anchor expression @ these points. ^# line starting #, , ^$ empty line (since there's nothing between start , end).

-v in grep negates match, command looking lines aren't commented out (not starting #), or empty.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User