$ cat get.num echo The number of arguments is: $# $The program simply displays the number of arguments with which it is invoked. For example:
$ get.num test out this program The number of arguments is: 4 $You can write a simple shell program to demonstrate ``$*''. Create a shell program called show.param that will echo all the parameters. Use the command line shown in the following completed file:
$ cat show.param echo The parameters for this command are: $* $The program show.param will echo all the arguments you give the command. Make show.param executable and try it using these parameters:
Hello. How are you? $ show.param Hello. How are you? The parameters for this command are: Hello. How are you? $Notice that show.param echoes
Hello. How are you?Now try show.param using more than nine arguments:
$ show.param a b c d e f g h i j The parameters for this command are: a b c d e f g h i j $Once again, show.param echoes all the arguments you give. The ``$*'' parameter can be useful if you use filename expansion to specify arguments to the shell command.
Use the filename expansion feature with your show.param command. For example, suppose you have three files in your directory named for the first three chapters of a book. The show.param command prints a list of all those files.
$ show.param chap? The parameters for this command are: chap1 chap2 chap3 $