Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hod do I tell shell script to go to next step if condition becomes true.
like
Code:
declare count[9]=( 2 3 4 5 6 7 7 5 2)
for (i=0;1<8;1++)
do
if $count[i] =2
next
else
echo $count[i];
done
Thanks.
You're looking for 'break' instead of 'next'. From the bash man page:
Code:
break [n]
Exit from within a for, while, until, or select loop. If n is
specified, break n levels. n must be >= 1. If n is greater than
the number of enclosing loops, all enclosing loops are exited.
The return value is 0 unless the shell is not executing a loop
when break is executed.
You also need to look at the syntax for 'if' and 'test' in the Bash man pages; I think that there are some issues in your code.
declare dir[8]=( 2 3 4 6 7 6 5 2)
echo " here are all the directories"
echo "-------------------------------"
for ((i=0;i<=7; i++))
do
if [ ${dir[0]} -eq 2 ] ; then
skip
else
# [ ${dir[0]} -ne 2 ] ; then
echo '${dir[0]}'
fi
done
I need to print every thing but 2.
If i am able to explain it better.
Last edited by knockout_artist; 11-02-2007 at 03:02 PM.
declare dir[8]=( 2 3 4 6 7 6 5 2)
echo " here are all the directories"
echo " ----------------------------"
for ((i=0;i<=7; i+=1))
do
if [ ${dir[$i]} -eq 2 ] ; then
continue
else # [ ${dir[0]} -ne 2 ] ; then
echo "${dir[$i]}"
fi
done
by the way, the use of the array is interesting, but I think it's overkill. If I were writing this, it would have looked like this:
Code:
echo " here are all the directories"
echo " ----------------------------"
for dir in 2 3 4 6 7 6 5 2
do
if [ $dir -eq 2 ] ; then
continue
else
echo "$dir"
fi
done
^ thank you very much.
I think you have solved the issue for me.
The 2 reasons I have used array, eventually this array will hold the names of directories.
Code:
if
read only
continue
else
chmod -R
fi
Plus most of the programming I have done is in C :-)
Last edited by knockout_artist; 11-03-2007 at 01:46 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.