Home » Questions » Computers [ Ask a new question ]

How to write a script to accept any number of command line arguments? (UNIX, BASH)

How to write a script to accept any number of command line arguments? (UNIX, BASH)

I have a script that I want to accept any number of command line arguments.

Asked by: Guest | Views: 122
Total answers/comments: 1
Guest [Entry]

"""$@"" does not solve his problem of ""ANY number of arguments"". there is a limit in how long a commandline can be (http://www.in-ulm.de/~mascheck/various/argmax/). a better way to read in ""unlimited arguments"" is via STDIN:

prg_which_creates_arguments | while read a; do \
echo ""do something with $a""; \
done

just create the arguments and pipe them one after another at the code which is doing something with them."