How to Use a Variable as Integer?

hello,
i am writing a script that takes the UID from the PASSWD and then i want
to increse the Number by one. for the Next user.
i cannot get this to work that a variable is as interger
example:

set i = 0
set $i = $+1

it's in tcsh if it's mather

i=0
i=`expr $i + 1`

don't use blank space while assigning some value to a variable.

1 Like

Thanks , can maybe tell me why this command does not work

Number = tail -1 /etc/passwd | awk -F":" '{ $3 }'

i want to put the UID of a user into a variable as a number andsd the increse by 1

 
Number=`tail -1 /etc/passwd | awk -F":" '{ $3 }'`
or
Number=$(tail -1 /etc/passwd | awk -F":" '{ $3 }')

Make sure there is no space between the = and Number

it does not work take a look:

bash-3.00# i=$(tail -1 /etc/passwd | awk -F":" '{ $3 }')
awk: illegal statement 603350
 record number 1
bash-3.00# echo $i

bash-3.00#
 
Number=`tail -1 /etc/passwd | awk -F":" '{ print $3 }'`
1 Like

Works Like a Charm now.Thanks alot

---------- Post updated at 07:09 AM ---------- Previous update was at 05:34 AM ----------

in regards on that subject i need to use the parameters for SSH Command:

ssh -t user@server2'/usr/loca/bin/sudo useradd -u $UsrID -g 1007 -s /bin/tcsh -d $hm$fl $fl'

OUTPUT:
UsrID: Undefined variable.

why isn't the syntax ok ?

 
ssh -t kplus@serv-condor-prod02 "/usr/loca/bin/sudo useradd -u $UsrID -g 1007 -s /bin/tcsh -d $hm$fl $fl"

when i do that is sayd /usr/loca/bin/sudo : command not found

check the spelling... seems you blindly running the commands :frowning:

i guess it must be local

Because variable expansion does not happen within single quotes.