27.5. Output Command-Line Arguments One by One
Go to http://examples.oreilly.com/upt3 for more information on: showargs
When you're experimenting with shell quoting, it's nice to be able to see how arguments on a command line are quoted. Here's a demo of a simple bash script named showargs; you might want to save it in a file and run it yourself (Section 35.1). The script shows how many arguments were passed to it. Then it lists the arguments, one per line, surrounded by >> << to show leading or trailing spaces.
% cat showargs #!/bin/bash test $# -ne 1 && s=s echo "I got $# argument$s:" for arg do echo -E ">>$arg<<" done % showargs "Start of path:" $path[1-3] " that's it! " I got 5 arguments: >>Start of path:<< >>/u/jpeek/bin<< >>/bin<< >>/usr/bin<< >> that's it! <<
The output from your shell may differ from that shown above, which is the result of running showargs in tcsh. bash doesn't have a $path variable, for example. And zsh expects a comma, rather than a hyphen, to separate the range. But as long as the arguments to showargs are quoted properly, you should get the result you're looking for, with a little tweaking, of course!
--JP and SJC
Copyright © 2003 O'Reilly & Associates. All rights reserved.