
Untitled
By: a guest on
May 27th, 2012 | syntax:
None | size: 0.89 KB | hits: 15 | expires: Never
bash Command line substitution in for loop
`#!/bin/bash
for((i=1;i<"$#";i++)) do
printf "Position %s of argumentArray has %s n", $i $(($i))
done`
for((i=1;i<"$#";i++)) do
printf "Position %s of argumentArray has %s n", $i $"$( eval echo $i )"
done
./test.sh first second third
Position 1 of argumentArray has 1
Position 1 of argumentArray has 2
Position 1 of argumentArray has 3
Position 1 of argumentArray has first
Position 1 of argumentArray has second
Position 1 of argumentArray has third
for((i=1;i<="$#";i++))
do
case "$($i)" in
.......
arguments=($@)
for ((i = 0; i < ${#arguments[@]}; i++)); do
echo "arguments[$i] = ${arguments[$i]}"
done
$ ./args.sh first second third
arguments[0] = first
arguments[1] = second
arguments[2] = third
for((i=1;i<=$#;i++)) do
printf "Position %s of argumentArray has %s n" $i "${!i}"
done