Hey Guys, I can not find the corrent syntax for what I am trying to acheive with a while loop. Having said that I'm not exactly sure what you would call it so I have been googling with no success probably for that reason. I am just working with some sub directories except there is one I don't want to use so I have a while loop like the following; if we stubmle into the sub directory I wish to leave alone then there is an IF statement and I have used the break command which is wrong, I don't want to end this whole loop I just want to skip onto the next increment of the loop as it were skipping this sub directory. Break is the wrong command but what should it be? Sorry I can't be any clearer but I don't know exactly what you would call this (which is why I am having no success finding it for my self!) #!/bin/bash find ./ -maxdepth 1 -type d | while read FOLDER do if [ $FOLDER == "./not_this_folder_oh_no!" ]; then break fi <otherwise do some magic here> done Many thanks for your time and input. Regards, James ;) -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V- PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++ ------END GEEK CODE BLOCK------ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20090603/600efe59/attachment-0001.html>
On Wed, Jun 03, 2009 at 08:44:29AM +0100, James Bensley wrote: There are many ways to do this; building on your code snippet it would be: #!/bin/bash find ./ -maxdepth 1 -type d | while read FOLDER do if [ "$FOLDER" = "./not_this_folder_oh_no!" ]; then continue fi <otherwise do some magic here> done "continue" is treated as a reloop operator; and you should quote strings. John -- "I'm sorry but our engineers do not have phones." As stated by a Network Solutions Customer Service representative when asked to be put through to an engineer. "My other computer is your windows box." Ralf Hildebrandt <sxem> trying to play sturgeon while it's under attack is apparently not fun. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: <http://lists.centos.org/pipermail/centos/attachments/20090603/822109f8/attachment-0001.sig>
Thanks guys the "continue" command was what I was looking for. Also to those who pointed out the lack of quotation marks around the string, they are on my original script but somehow vanished during the copy and paste operation between my shell window and browser...werid?!?! Still If I hadn't of had those then you would of corrected me so thanks for that! Nice work listee's ;) -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V- PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++ ------END GEEK CODE BLOCK------ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20090603/4935bad5/attachment-0001.html>
On Wed, 2009-06-03 at 02:59 -0500, John R. Dennison wrote:> On Wed, Jun 03, 2009 at 08:44:29AM +0100, James Bensley wrote: > > There are many ways to do this; building on your code > snippet it would be: > > #!/bin/bash > find ./ -maxdepth 1 -type d | while read FOLDER > do > if [ "$FOLDER" = "./not_this_folder_oh_no!" ]; then > continue > fi > <otherwise do some magic here> > done > > "continue" is treated as a reloop operator; and you should quote strings.--- I'm no Bash expert but is there a real good reason "pass" would not be used in place of continue? I'm just really currious.... JohnStanley
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 James Bensley wrote:> Hey Guys, > > I can not find the corrent syntax for what I am trying to acheive with a > while loop. Having said that I'm not exactly sure what you would call it > so I have been googling with no success probably for that reason. > > I am just working with some sub directories except there is one I don't > want to use so I have a while loop like the following; if we stubmle > into the sub directory I wish to leave alone then there is an IF > statement and I have used the break command which is wrong, I don't want > to end this whole loop I just want to skip onto the next increment of > the loop as it were skipping this sub directory. Break is the wrong > command but what should it be? Sorry I can't be any clearer but I don't > know exactly what you would call this (which is why I am having no > success finding it for my self!) > > #!/bin/bash > find ./ -maxdepth 1 -type d | while read FOLDER > do > if [ $FOLDER == "./not_this_folder_oh_no!" ]; then > break > fi > <otherwise do some magic here> > done > > Many thanks for your time and input. > Regards, > James ;)Reverse the logic in the test and consolidate further #!/bin/bash find ./ -maxdepth 1 -type d | while read FOLDER do if [ $FOLDER != "./not_this_folder_oh_no!" ]; then <do some magic here> fi done Or exclude the directory in the find command itself #!/bin/bash find ./ -maxdepth 1 -type d -wholename './not_this_folder' -prune -o - -print | while read FOLDER do <do some magic here> done - -- David Goldsmith -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkoqsu4ACgkQ417vU8/9QfkyXQCfXXeVhiREuESbs5aV4qXPXLi+ ZKkAoKfqqytzt8GBwf7CCVxrwooL5Ouu =Av57 -----END PGP SIGNATURE-----