I'm new at Command Lines! I want to use awk in order to print the number of files given in the command line. When I'm trying to do this I go in an endless loop.

awk 'BEGIN{};'
awk 'END{print ARGC}'

It sarts reading the files but I don't know how to stop it.

1 Answer 1


correct syntax is

awk 'END {print ARGC}' file1 ... filen 

be aware that

  • file must be given (elase awk will wait for input in stdin
  • awk itself count as one in ARGC

to get number of file

awk 'END {print ARGC-1}' file1 ... filen

endless loop

(this should be a comemnt, as nothing give a clues as to why).

suppose you write

 foobar="/my/path1 /other/path2"
 C=$(awk 'END{ print ARGC-1}' $fobar)

you are likely to go in endless loop/witing for stdin as you mispell $foobar as $fobar.

  • Thank you! And if I want to make a shell script with it how should I write? It also goes in an endless loop. :(
    – Mary
    Mar 28, 2017 at 11:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .