Re: about loop (97 Views)
Reply
Regular Advisor
kamal_15
Posts: 109
Registered: ‎12-21-2004
Message 1 of 7 (97 Views)

about loop

hi all

Iam new in script
I create a simple script to list all files and directory in current dir
*********
for i in *
if [ -d $i ]
then
echo $i "Directory"
fi
------> I wnant to go next i and esc the next
(what command i put here to do that?)
echo $i
done
********************
thankx

kamal
Please use plain text.
Honored Contributor
Leif Halvarsson_2
Posts: 6,682
Registered: ‎01-09-2002
Message 2 of 7 (97 Views)

Re: about loop

Hi,

Do I understand you correct ?

Something like:

for i in *
do
if [ -d $i ]
then
echo $i "Directory"
else
echo $i "File"
fi
done
Please use plain text.
Regular Advisor
kamal_15
Posts: 109
Registered: ‎12-21-2004
Message 3 of 7 (97 Views)

Re: about loop

thank u for your response
that is true in this example
but
in other case
if i want to esc the next lines and continue
next i

is there any way to do that ?

thankx
Please use plain text.
Honored Contributor
Leif Halvarsson_2
Posts: 6,682
Registered: ‎01-09-2002
Message 4 of 7 (97 Views)

Re: about loop

Hi,
Could you please describe more in detail.
Which "lines" do you want to esc (skip ?) ?
Please use plain text.
Honored Contributor
Andreas Voss
Posts: 1,364
Registered: ‎10-14-1997
Message 5 of 7 (97 Views)

Re: about loop

Hi,

perhaps this is what you are looking for:

for i in *
if [ -d $i ]
then
echo $i "Directory"
fi
continue
echo $i
done

the code is not very useful but you might learn somthing by that.

Regards
Please use plain text.
Regular Advisor
kamal_15
Posts: 109
Registered: ‎12-21-2004
Message 6 of 7 (97 Views)

Re: about loop

I mean

if any one familer with visual basic
*********************************************
for x = 1 to 10
if (any condition) then
(do any thing)
next x ---> (this command return to x again without complete the next lines ).
end if

(any thing)
next
********************************************


i want to know what is this command in unix ?
Please use plain text.
Honored Contributor
Leif Halvarsson_2
Posts: 6,682
Registered: ‎01-09-2002
Message 7 of 7 (97 Views)

Re: about loop

Hi,

I can give you two examples that will do the same job as the example in basic. Example two is a "direct" translation but the syntax in example 1 should be prefered.


for i in 1 2 3 4 5 6 7 8 9 10
do
if [ (any condition) ]
then
(do something)
else
(do something else)
fi
done

for i in 1 2 3 4 5 6 7 8 9 10
do
if [ (any condition) ]
then
(do something)
continue
fi
(do something else)
done


for x = 1 to 10
if (any condition) then
(do any thing)
next x ---> (this command return to x again without complete the next lines ).
end if

(any thing)
next



Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation