Difference between revisions of "Positional parameters set"

From assela Pathirana
Jump to navigationJump to search
 
Line 1: Line 1:
Follwing is an example of positional parameters created by command line arguments being later replaced by others.  
Following is an example of positional parameters created by command line arguments being later replaced by others.
<pre>
<pre>
#!/bin/bash
#!/bin/bash
Line 11: Line 11:
echo '$3=' $3
echo '$3=' $3
</pre>
</pre>
The first <tt>echo</tt> statements will print the command line arguments; but the second set will print the first three files in the current directory! The <tt>set</tt> command replace the positional parameters with the output of <tt>ls</tt> command.  
The first <tt>echo</tt> statements will print the command line arguments; but the second set will print the first three files in the current directory! The <tt>set</tt> command replace the positional parameters with the output of <tt>ls</tt> command.


[[Category:Computing]]
[[Category:Computing]]

Revision as of 12:25, 6 April 2006

Following is an example of positional parameters created by command line arguments being later replaced by others.

#!/bin/bash
#try calling this with several arguments
echo '$1=' $1
echo '$2=' $2
echo '$3=' $3
set `ls`
echo '$1=' $1
echo '$2=' $2
echo '$3=' $3

The first echo statements will print the command line arguments; but the second set will print the first three files in the current directory! The set command replace the positional parameters with the output of ls command.