Bash Script Returns Triple The Results Then It Would If Doing It Manually, Why?
Please review the following script and let me know what the issue is.
Code:
#!/bin/bash Code:
find /usr/lib -type f -perm +022 -exec stat -c %a:%n {} \ thanks |
Change:
Code:
do find $DIRS -type f -perm +022 -exec stat -c %a:%n {} \;; Code:
do find $DIR -type f -perm +022 -exec stat -c %a:%n {} \;; Alternatively you could avoid the for loop altogehter by just doing: Code:
#!/bin/bash |
Simple syntax error, thanks.
I still get confused on the for statement. The i is a variable and the other part if what we are looping thru, correct? |
$DIRS is everything found where $DIR is each item in the list.
|
Quote:
I prefer to put names on variables because it gives me a clue later in long scripts what the variable relates to. I probably woulnd't have chosen DIRS and DIR given how close in name they are. I might have made first variable DIRLIST and the other DIR (or EACHDIR) to differentiate them but again its just a matter of preference. As shown, you can do what you want with DIRS and DIR. |
I agree with MensaWater; always go out of your way to make the 'list' var and 'item' var names sufficiently different that you won't get stung like that :)
You'll thank us later ;) As a general rule I almost never use just $i or equiv as loop vars any more. For one thing you may have >1 loop in same file or set of files ... |
All times are GMT -5. The time now is 10:19 PM. |