This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Members
8166 Online
This widget could not be displayed.
Solutions
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
New Discussion

Re: about loop

 
kamal_15
Regular Advisor

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
6 REPLIES 6
Leif Halvarsson_2
Honored Contributor

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
kamal_15
Regular Advisor

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
Leif Halvarsson_2
Honored Contributor

Re: about loop

Hi,
Could you please describe more in detail.
Which "lines" do you want to esc (skip ?) ?
Andreas Voss
Honored Contributor

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
kamal_15
Regular Advisor

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 ?
Leif Halvarsson_2
Honored Contributor

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