Difference between revisions of "Positional parameters set"

From assela Pathirana
Jump to navigationJump to search
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Follwing is an example of positional parameters created by command line arguments being later replaced by others.  
{{Template:needs-cygwin-or-linux}}
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 12:
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]]

Latest revision as of 13:00, 6 April 2006

Green info.gif

The commands on this page can be tried out on Cygwin installed in a windows PC or on any UNIX computer.

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.