You can move through an argument list using the shift command. Here's an example using an inline while loop and and an inline for loop.
# sh
The while loop
# set M Y S Y S A D B L O G
# while [ $# -gt 0 ]
> do
> echo $*
> shift
> done
M Y S Y S A D B L O G
Y S Y S A D B L O G
S Y S A D B L O G
Y S A D B L O G
S A D B L O G
A D B L O G
D B L O G
B L O G
L O G
O G
G
The for loop
# set M Y S Y S A D B L O G
# for i in $*
> do
> echo $*
> shift
> done
M Y S Y S A D B L O G
Y S Y S A D B L O G
S Y S A D B L O G
Y S A D B L O G
S A D B L O G
A D B L O G
D B L O G
B L O G
L O G
O G
G
This blog covers Unix system administration HOWTO tips for using inline for loops, find command, Unix scripting, configuration, SQL, various Unix-based tools, and command line interface syntax. The Unix OS supports tasks such as running hardware, device drivers, peripherals and third party applications. Share tips/comments. Read the comments. But most importantly: Read Disclaimer - Read Disclaimer.
Subscribe to:
Post Comments (Atom)
1 comment:
this is good to understand shift
Post a Comment