What is a type of this variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is a type of this variable?
# 1  
Old 08-04-2011
What is a type of this variable?

I have a question about the type of this variable
checkU= sudo cat /etc/passwd: grep $uname: wc -l

I write a script to check the existent of username that get from the keyboard. If there is no username,it will create the username else it show the 'Duplicate name" message.

The problem is it always show 'Duplicate name' although there is not that username in the system.
What do I write wrong? I use the wrong operator?

This is the section of script that have a problem:

Code:
checkU=sudo cat /etc/passwd: grep $uname: wc -l
if [ "$checkU" = "0" ] ; then
       useradd -c "$fullname" $uname
       echo OK
else
        echo Duplicate name
fi

# 2  
Old 08-04-2011
Code:
 
"$checkU" = "0"
 
should be 
 
"$checkU" == "0"

what shell you are using ?
# 3  
Old 08-04-2011
bourne shell
# 4  
Old 08-04-2011
Try this..

Code:
checkU=`grep -c $uname /etc/passwd`
[ "$checkU" -gt "0" ] && echo "Duplicate Name" || useradd -c "$fullname" $uname

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 08-04-2011
Quote:
Originally Posted by itkamaraj
Try this..

Code:
checkU=`grep -c $uname /etc/passwd`
[ "$checkU" -gt "0" ] && echo "Duplicate Name" || useradd -c "$fullname" $uname


It's work. thank you!!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Strange value of the double type variable: -nan(0x8000000000000)

I am confused by the value of "currdisk->currangle" after adding operation. Initially the value of "currdisk->currangle" is 0.77500000000000013, but after adding operation, it's changed to "-nan(0x8000000000000)", Can anyone explain ? Thanks! The following is the occasion of gdb debugging. 3338 ... (8 Replies)
Discussion started by: 915086731
8 Replies

2. Programming

C++ type-casting a member variable in const methods

Is it permitted to type-cast a member variable passed in as a parameter in a member const method .. I am doing something like : in a return-type method () const { variable other = long(member variable) } this other assigned variable is not updating and I wonder if type-casting in such... (1 Reply)
Discussion started by: shriyer123
1 Replies

3. Shell Programming and Scripting

Perl variable type assessment

Hello experts, How we can find out,that what is type of a scalar variable? i.e a scalar var contain a number or a string. Thanks in advance. (8 Replies)
Discussion started by: Zaxon
8 Replies

4. Programming

Need help in storing command line argument argv[2] to a variable of int type

The following program takes two command line arguments. I want the second argument (fileCount) to be stored/printed as a int value. I tried my best to typecast the char to int (check the printf statement at last) but is not working...the output is some junk value. This program is in its... (3 Replies)
Discussion started by: frozensmilz
3 Replies

5. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

6. Shell Programming and Scripting

getting type of variable

Hello: Is there any way to tell the type of a passed or entered variable, if it is a string or integer,...etc. Thanks a lot (2 Replies)
Discussion started by: aladdin
2 Replies

7. Shell Programming and Scripting

String type to date type

Can one string type variable changed into the date type variable. (1 Reply)
Discussion started by: rinku
1 Replies

8. Shell Programming and Scripting

how to get type of variable in perl

hello all how can i get the type of variable in perl like typeof(var); in javascript for instance ? to know if the variable is int or string ? (2 Replies)
Discussion started by: umen
2 Replies

9. Shell Programming and Scripting

Problem with variable type

Dear All, I am trying to write an script to calculate geometric centre of selected residues of a protein structure. Say I have a PDB file (a text containing the x, y, and z coordinates of atoms of a protein). I want to extract the X coordinates of the atoms belonging to the interested residues... (2 Replies)
Discussion started by: siavoush
2 Replies
Login or Register to Ask a Question