Unix script giving error trying to assign variable? -


i'm extremely new unix, , driving me crazy. getting error:

./lines: line 21: [[: grep -c *.* $3: syntax error: operand expected (error toke                                           n ".* $3") ./lines: line 26: [[: grep -c *.* $3: syntax error: operand expected (error toke n ".* $3") 

when running script:

#!/bin/bash #lines <start> <finish> <file> prints lines start-finish of file  if [[ $# != 3 ]]    echo "command format: lines <starting line> <end line> <filename>"     exit fi  tlines='grep -c *.* $3' start=$1 finish=$2  if [[ $finish -lt $start ]]     echo "$finish less $start. i'll go ahead , reverse you."     start=$2     finish=$1 fi  start=$((finish-start+1))  if [[ $tlines -lt $start ]]      echo "$3 $tlines lines - that's less $start"     exit fi  if [[ $tlines -lt $finish ]]     echo "3 $tlines line - that's less $finish"     exit fi head -$finish $3 | tail -$start exit 

i have no idea errors mean , searching them online have not given me insight. appreciate help!

seems wanted use command substitution here:

tlines='grep -c *.* $3' 

but used wrong quotes. correct ones legacy backticks:

tlines=`grep -c *.* $3` 

or newer form:

tlines=$(grep -c *.* $3) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -