0

I'm trying to have a variable $totalLines that stores the total lines in a file (given as input $1).

I'm trying to do something like this:

totalLines= grep -c *.* $1

But Unix doesn't like that.

I've tried enclosing it in paranthesis, square brackets, and (), but that doesn't work either. This has got to be super simple but I'm searching for the answer around the web and not finding a page or forum that clearly states it.

Sorry to trouble you guys with such an easy one.

0

2 Answers 2

2

There are two ways to achieve it:

totalLines=$(grep -c *.* $1)

or

totalLines=`grep -c *.* $1`
Sign up to request clarification or add additional context in comments.

1 Comment

the $(...) form only works with some shells, such as bash and zsh. It won't work with csh or sh
1

Like: totalLines=$(grep -c *.* $1)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.