IF statement help
Hi chaps,
* Can you help me with an if statement? * I have the following which checks for the existence of a folder ($1) in two locations ($folder1_source and $folder2_source). First it checks in the $folder1_source location then in the $ folder2_source location. If it finds it in neither then the $folder_source variable remains empty and the script quits. * **************** folder_source="" if [ -d /$folder1_source/$1 ]; then *************** folder_source=1 elif [ -d /$folder2_source/$1 ]; then *************** folder_source=2 elif [ $folder_source="" ]; then *** exit fi ***************** * I want to add one more check which is that if the directory specified by the $1 variable is found in BOTH the /$folder1_source AND /$folder2_source locations then I want the script to fail. * Whats the best way of writing that last elif statement? * Olly * -- G2 Support Network Support : Online Backups : Server Management * * Tel:*** 0845 307 3443 Email:* oliver.marshall@g2support.com Web:*** http://www.g2support.com Twitter: g2support Newsletter: http://www.g2support.com/newsletter Mail:** 2nd Floor, 130a Western Rd, Brighton, Sussex, BN12LA * G2 Support LLP is registered at Mill House, 103 Holmes Avenue, HOVE BN3 7LE. Our registered company number is OC316341. * * -- ubuntu-users mailing list ubuntu-users@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users |
IF statement help
2009/11/11 Oliver Marshall <Oliver.Marshall@g2support.com>
Hi chaps, * Can you help me with an if statement? * I have the following which checks for the existence of a folder ($1) in two locations ($folder1_source and $folder2_source). First it checks in the $folder1_source location then in the $ folder2_source location. If it finds it in neither then the $folder_source variable remains empty and the script quits. * **************** folder_source="" if [ -d /$folder1_source/$1 ]; then *************** folder_source=1 elif [ -d /$folder2_source/$1 ]; then *************** folder_source=2 elif [ $folder_source="" ]; then *** exit fi ***************** * I want to add one more check which is that if the directory specified by the $1 variable is found in BOTH the /$folder1_source AND /$folder2_source locations then I want the script to fail. * Whats the best way of writing that last elif statement? * Olly * -- G2 Support Network Support : Online Backups : Server Management * * Tel:*** 0845 307 3443 Email:* oliver.marshall@g2support.com Web:*** http://www.g2support.com Twitter: g2support Newsletter: http://www.g2support.com/newsletter Mail:** 2nd Floor, 130a Western Rd, Brighton, Sussex, BN12LA * G2 Support LLP is registered at Mill House, 103 Holmes Avenue, HOVE BN3 7LE. Our registered company number is OC316341. * * -- ubuntu-users mailing list ubuntu-users@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users Hi, maybe you can folder_source="" if [ -d /$folder1_source/$1 ]; then *************** folder_source=1 elif [ -d /$folder2_source/$1 ]; then *************** folder_source=2 elif [ $folder_source=""* ] || [ $folder_source="1"* ] && [ $folder_source="2"* ]; then *** exit fi Best regards, -- Matteo Filippetto -- ubuntu-users mailing list ubuntu-users@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users |
IF statement help
Oliver Marshall wrote:
> I have the following which checks for the existence of a folder ($1) > in two locations ($folder1_source and $folder2_source). First it > checks in the $folder1_source location then in the $ folder2_source > location. If it finds it in neither then the $folder_source variable > remains empty and the script quits. > > **************** > folder_source="" > if [ -d /$folder1_source/$1 ]; then > folder_source=1 > elif [ -d /$folder2_source/$1 ]; then > folder_source=2 > elif [ $folder_source="" ]; then What do you want to achieve with this statement? Did you perhaps mean elif [ $folder_source = "" ]; then instead? > exit > fi > ***************** > I want to add one more check which is that if the directory specified > by the $1 variable is found in BOTH the /$folder1_source AND > /$folder2_source locations then I want the script to fail. I would change the entire block like this: test -d "/$folder1_source/$1" -a -d "/$folder2_source/$1" && exit 1 test ! -d "/$folder1_source/$1" -a ! -d "/$folder2_source/$1" && exit 2 test -d "/$folder1_source/$1" && folder_source=1 test -d "/$folder2_source/$1" && folder_source=2 > Whats the best way of writing that last elif statement? There is no _best_ way. :) Nils -- ubuntu-users mailing list ubuntu-users@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users |
IF statement help
matteo filippetto wrote:
> Hi, > > maybe you can > > folder_source="" > > if [ -d /$folder1_source/$1 ]; then > > folder_source=1 > > elif [ -d /$folder2_source/$1 ]; then > > folder_source=2 > > elif [ $folder_source="" ] || [ $folder_source="1" ] && [ > $folder_source="2" ]; then This is incorrect. First, either the if or the elif could execute but never both. Even if they did both execute, folder_source obviously can't equal two different values at the same time. Nils's solution appears correct. Matthew Flaschen -- ubuntu-users mailing list ubuntu-users@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users |
| All times are GMT. The time now is 03:59 AM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.