Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Oct 2006 23:36:12 -0700
From:      Garrett Cooper <youshi10@u.washington.edu>
To:        freebsd-questions@freebsd.org
Subject:   Bug with tcsh? : if evaluating true instead of false
Message-ID:  <453F05DC.6070906@u.washington.edu>

next in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ok, so I tried to make a simple script to add users so I wouldn't have
to type in groups/pw over and over again... the problem is that it's not
behaving like it should =o.

Script:
#!/bin/tcsh -x
#

if ( ( $# != 0 ) ) {

        set GROUPS="";
        set USER="";

        if( ( $# == 2 ) ) {

                set USER=$1;
                set GROUPS=$0;

                switch($0)

                        case "-v":
                                set GROUPS="-G vip";
                                breaksw

                        case "-w":
                                set GROUPS="-G vip,wheel";
                                breaksw
                        default:
                                echo "bad argument(s) specified!";
                                exit(1);

                endsw

        } else if($# == 1) {
                set USER=$0;
        } else {
                echo "bad # of args; exiting..";
        }

        `pw add user -N -d /home/$USER -s /usr/local/bin/bash $GROUPS
$USER && mkdir /home/$USER && ln -s /home/dud.bash_login
/home/$USER/.bash_login`;

} else {
        print "Usage [-r|-v|-w] username"
}

Output:
[root@hoover ~]# ./mkuser
if ( ( 0 != 0 ) ) {
set GROUPS=
set USER=
if ( ( 0 == 2 ) ) {
set USER=
set GROUPS=./mkuser
switch ( ./mkuser )
echo bad argument(s) specified!
bad argument(s) specified!
exit ( 1 )

	Basically it should drop out at the first if statement due to 0 != 0
being true and go straight to the else block, but it's falling through
to the switch statement. Any ideas?

	Also..

[root@hoover /home/gcooper]# tcsh --version
tcsh 6.14.00 (Astron) 2005-03-25 (i386-intel-FreeBSD) options
wide,nls,dl,al,kan,rh,color,filec

	Thanks!

- -Garrett
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPwXc6CkrZkzMC68RAo4sAJ9LOcJ6xnjTo2pWF8W6nOjqXqjfmACeP9OC
WQWFzBpbKca+kkdT1APlo3k=
=G6sT
-----END PGP SIGNATURE-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?453F05DC.6070906>