how to check if a string consist of any space?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to check if a string consist of any space?
# 8  
Old 07-30-2008
test -z $username expands to test -z a b which is a syntax error, because test -z only expects one argument. By adding double quotes, like test -z "$username", the expansion becomes test -z "a b" which has only a single, double-quoted argument. That will fix the syntax error.

However, test -z only checks for an empty string, but will treat a string with characters in it (even if they are blanks) as non-empty. I would recommend that you try the case approach instead. If it doesn't work, perhaps you can follow up here.

Not to sound too harsh, but I already explained this in https://www.unix.com/unix-dummies-que...#post302219402
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

2. Homework & Coursework Questions

Looking to check disk space

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to check the disk space and if any portion disk space usage high then write to one file, later will... (5 Replies)
Discussion started by: Jasminshakoor
5 Replies

3. Shell Programming and Scripting

Check if line has a space

Hi, I want to check if the given line from a text file has a spaces in between. if it does, then I want to add '"' double quotes at the beginning and end of the line. Otherwise leave the line as it is. For example, below is the sample content from my file. $cat file.txt test1 test2... (6 Replies)
Discussion started by: svajhala
6 Replies

4. Programming

Value printed by gdb does not consist with the right value

Hello, I find the value printed by gdb does not consist with the right value.The following is the output. (gdb) 7 while ( ( optc = getopt(argc, argv, ":b:B:h" ) ) != -1 ) { (gdb) 8 printf( "%c %d %s\n", optc, optind, optarg); (gdb) B 5 1-2 7 while ( ( optc =... (1 Reply)
Discussion started by: 915086731
1 Replies

5. Shell Programming and Scripting

Need to build Shell Script to search content of a text file into a folder consist several files

Have to read one file say sourcefile containing several words and having another folder containing several files. Now read the first word of Sourcefile & search it into the folder consisting sevral files, and create another file with result. We hhave to pick the filename of the file in which... (3 Replies)
Discussion started by: mukesh.baranwal
3 Replies

6. Shell Programming and Scripting

how to check disk space

Hi All, pls go thru the below code and help me. when i check "df -k" in my solaris system .. it will show like below.. fd 0 0 0 0% /dev/fd /dev/dsk/c0t0d0s3 20171281 2319266 17650303 12% /var /dev/dsk/c0t0d0s4 10085260 443854... (15 Replies)
Discussion started by: steve2216
15 Replies

7. Solaris

Disk space check

Hi, I have a question regarding finding free space on the disk of a solaris machine. Many mount points are available in my machine. Right now i am using df -b option to get the free disk space available. I have an assignment to check free space on the disk. I pass the directory as a... (6 Replies)
Discussion started by: raghu.amilineni
6 Replies

8. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

9. Shell Programming and Scripting

check space !!!

The have written the below script :- ============================ SPACE=`bdf /DATA_TRANSFER|awk '{print $4}' |grep "%"` TEST="96%" if then echo "Continue ....." sleep 2 else echo " Current space for DATA_TRANSFER is less than 02 %" echo " Pls clear space and than continue ....."... (2 Replies)
Discussion started by: kamlesh_p
2 Replies

10. Shell Programming and Scripting

Check directory space?

Is there some command I can use to check to see if there is 2 Gig of space available in a directory before I created a 2 Gig file? (3 Replies)
Discussion started by: lesstjm
3 Replies
Login or Register to Ask a Question
Tcl_GetInt(3)						      Tcl Library Procedures						     Tcl_GetInt(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_GetInt, Tcl_GetDouble, Tcl_GetBoolean - convert from string to integer, double, or boolean SYNOPSIS
#include <tcl.h> int Tcl_GetInt(interp, string, intPtr) int Tcl_GetDouble(interp, string, doublePtr) int Tcl_GetBoolean(interp, string, boolPtr) ARGUMENTS
Tcl_Interp *interp (in) Interpreter to use for error reporting. CONST char *string (in) Textual value to be converted. int *intPtr (out) Points to place to store integer value converted from string. double *doublePtr (out) Points to place to store double-precision floating-point value converted from string. int *boolPtr (out) Points to place to store boolean value (0 or 1) converted from string. _________________________________________________________________ DESCRIPTION
These procedures convert from strings to integers or double-precision floating-point values or booleans (represented as 0- or 1-valued integers). Each of the procedures takes a string argument, converts it to an internal form of a particular type, and stores the converted value at the location indicated by the procedure's third argument. If all goes well, each of the procedures returns TCL_OK. If string doesn't have the proper syntax for the desired type then TCL_ERROR is returned, an error message is left in the interpreter's result, and nothing is stored at *intPtr or *doublePtr or *boolPtr. Tcl_GetInt expects string to consist of a collection of integer digits, optionally signed and optionally preceded by white space. If the first two characters of string are ``0x'' then string is expected to be in hexadecimal form; otherwise, if the first character of string is ``0'' then string is expected to be in octal form; otherwise, string is expected to be in decimal form. Tcl_GetDouble expects string to consist of a floating-point number, which is: white space; a sign; a sequence of digits; a decimal point; a sequence of digits; the letter ``e''; and a signed decimal exponent. Any of the fields may be omitted, except that the digits either before or after the decimal point must be present and if the ``e'' is present then it must be followed by the exponent number. Tcl_GetBoolean expects string to specify a boolean value. If string is any of 0, false, no, or off, then Tcl_GetBoolean stores a zero value at *boolPtr. If string is any of 1, true, yes, or on, then 1 is stored at *boolPtr. Any of these values may be abbreviated, and upper-case spellings are also acceptable. KEYWORDS
boolean, conversion, double, floating-point, integer Tcl Tcl_GetInt(3)