Skip to content

Count Arguments In A Bash Script

Another useful tip I’m sure most people will be familiar with, but in bash scripts $# stores the number of arguments passed to the script. Eg, combine with $@ (all arguments) for batch processing (what I used it for):


foreach $arg in $@; do
[stuff]
[compare with $# to tell remaining items]
done

Very basic stuff, but it was new to me yesterday, and it might save someone a bit of time searching.

1 thought on “Count Arguments In A Bash Script”

  1. Pingback: Bertie Baggio's Wonderland » Count Arguments In A Bash Script Scripts Rss

Tell us what's on your mind

Discover more from Rob's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading