|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
alias checkk {
var %a = 1,%lev = $iif($1,$1,*)
while $ulist(*,%lev,%a) {
echo 4 -a -> %a $+($level($v1),:,$v1)
inc %a
}
}
I use the code above to scan what I have in users list, but how do you make it tell you there's nothing added in it using "else" ?
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
Try this:
alias checkk {
var %a = 1,%lev = $iif($1,$1,*)
if ($ulist(*,%lev,%a) == 0) echo 4 -a -> 0 results
while $ulist(*,%lev,%a) {
echo 4 -a -> %a $+($level($v1),:,$v1)
inc %a
}
}
-genius_at_work
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
I'm afraid nothing shows.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
alias checkk {
var %a = 1,%lev = $iif($1,$1,*)
if ($ulist(*,%lev,0) == 0) echo 4 -a -> 0 results
while $ulist(*,%lev,%a) {
echo 4 -a -> %a $+($level($v1),:,$v1)
inc %a
}
}
-genius_at_work
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
Fjord artisan
Joined: Apr 2006
Posts: 464 |
Doesnt that if statement require brackets?
...nvm, works fine without, so I guess not.
Last edited by OrionsBelt; 27/01/08 10:46 PM.
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
You can get away with not using { } if there's only one command to perform. The main thing to watch out for is this: if (x) echo -a this triggers when the if is $true | echo -a this triggers no matter what, whilst some would expect it to trigger only if the if was $true
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
Fjord artisan
Joined: Apr 2006
Posts: 464 |
Thanks for the explanation hixxy
Never knew that was possible
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
It's possible, and has been said to be faster. However, I personally find it harder to read quickly. I'd rather see the {}'s used appropriately than not, but that's just my personal preference. At the same time, I don't overdo the ()'s in IF's. if (this == that && that == this) {} instead of if (this == that) && (that == this) {} or if ((this == that) && (that == this)) {} I'll only add the extra ()'s when order of operation is needed. Again, just my personal preference. 
|
|
|
|
ots654685
|
ots654685
|
Nice piece of code, could come in handy here but have 1 question about it. It fit's more situations but ok. I never understood the loop mechanism and i'm trying to strip the output of this snippet.Fixed. alias checkk {
var %a = 1
if ($ulist(*,0) == 0) echo 4 -a -> 0 results
while $ulist(*,%a) {
echo @users -> %a $v1
inc %a
}
}
Last edited by ots654685; 31/03/08 02:57 PM.
|
|
|
|
ots654685
|
ots654685
|
After playing with this and modified it i noticed using levels is more handy for me but i can't manage to get out put sorted: now it gives me this -> 1 group1:user1!*user1@localhost -> 2 group2:user4!*user4@localhost -> 3 group2:user5!*user5@localhost -> 4 group1:user2!*user2@localhost -> 5 group1:user3!*user3@localhost -> 6 group2:user6!*user6@localhost
But i would like to see something like this group1 user1 user2 user3
group2 user4 user5 user6
Last part of <useraddress> (!*user6@localhost) is need for script but not needed in output but i don't know how to strip that.
More simple would be sorting user.ini and give that as output but i'm trying to understand current piece of code and extend it with other options
Last edited by ots654685; 01/04/08 04:35 PM.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
alias checkk {
var %a = 1,%lev = $iif($1,$1,*)
if ($ulist(*,%lev,0) == 0) echo 5 -a -> 0 results
while $ulist(*,%lev,%a) {
echo 6 -a -> User $+ $remove(%a,$null)$+($level(!$v1),$v1))
inc %a
}
} This might do the trick. I can get User1, User2, User3 etc...
|
|
|
|
ots654685
|
ots654685
|
@Tomao: That does the trick for sorting but still struggling with sorting it by group
echo output: group1 user1 user2 user3
group2 user4 user5 user6
Thanks for helping anyway
|
|
|
|
|