1828366 Members
2776 Online
109976 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
kholikt
Super Advisor

shell script

Hi,

I am writing a shell script that allow to pass argument

let said

myscript tape1:tape2:tape3 "hello world"

inside the script
$1=tape1:tape2:tape3
$2=hello world

I have a for loop that support to loop through tape1,tape2 and tape3. I will use IFS=: as the delimiter.

my question is in my for loop how could I loop through tape1:tape2:tape3

for i in $1
do
echo "$i"
done
abc
2 REPLIES 2
curt larson_1
Honored Contributor
Solution

Re: shell script

the easiest way is not to include the colons (:) in the passed argument, i.e. "tape1 tape2 tape3" instead of tape1:tape2:tape3
curt larson_1
Honored Contributor

Re: shell script

or you could do something like this:
print "$1" | tr ':' '\n' |
while read tape
do
echo $tape
done