![]() |
| ||
| too many arguments Does anyone know why this script would give me an error (only sometimes) with it saying "too many arguments"? #!/bin/bash Output: root@siduxbox:/home/eric# empty trash |
| ||
| Re: too many arguments Hey there, I can see two places where this script might get you. 1. Since you create parts of some arrays by using the wildcard asterisk (*) you run the risk of creating really long lists which could give you a problem with programs like "rm" which tap out after they reach their limit of characters (not shown here ;) 2. The other one is happening because there's nothing to empty and the x in your "for x" loop doesn't contain a value. I know there are better ways around this, but I generally would just do a cursory check on the array before iterating through it. For instance, if you took the value of: ${#arrDirs[@]} or ${#arrDirs[*]} If those counts equal zero, you can go to your "nothing to do message" and otherwise iterate through the array. Hope that helps some :) Happy THanksgiving ! , Mike |
| ||
| Re: too many arguments Sorry for a delayed response...should the else conditions take care of that? |
| ||
| Re: too many arguments I thought it was like this: If the DIR equal the DIR, then remove it. if it's anything else, then it's nothing. But what you're saying is to try: for x in "${arrDirs[@]}"; doCorrect? I guess that's right since it wouldn't equal anything else except for zero if its not there...but I thought that's what an else is for. Seems the same to me. |
| ||
| Re: too many arguments Hey again, The actual issue for you here, I think, is that every $x is going to equal $x. For this reason. Taking the top of your code: for x in "${arrDirs[@]}"; dothe "for x" is populating the variable x with the first value of @arrDirs, then the second, etc, until it's done. Within the loop, however, you're comparing x with x. It would seem that they would have to match because they're the exact same variable with the exact same value. It's possible you may be looking to do this: for x in "${arrDirs[@]}"; dowhere you'd just be checking if the value of x (the nth variable in the arrDirs array) exists and is a directory. let me know if I'm way off ;) Best wishes, Mike |
| ||
| Re: too many arguments That works! Except when i know there is nothing in the directories that I have emptied, or it doesn't exist, its not echoing... |
| ||
| Re: too many arguments Hey again :) With that revised code, change this bottom chunk, also, from: elif [ $x = 0 ]; then to else and you should be all set :) Best wishes, Mike |
| All times are GMT -4. The time now is 2:20 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC