Sponsored Content
Full Discussion: starting programmer
Top Forums UNIX for Dummies Questions & Answers starting programmer Post 302582662 by ryran on Friday 16th of December 2011 06:57:38 PM
Old 12-16-2011
In addition to what they said, since you're starting out and already mentioned you're using BASH: Don't use the classic shell builtin '[ expression ]' ; use the shell keyword '[[ expression ]]'. Trust me, it's all-around better, unless you're coding for old busted bourne shell systems.
One benefit: you won't have to worry about putting quotes around your variables, which was part of your problem.

The conditional expression [Bash Hackers Wiki]
 

7 More Discussions You Might Find Interesting

1. SCO

Need Sco Programmer

Need programmer to work on 8-12 month project near Dallas, Texas or can telecommute to make changes to SCO File Pro 32 UNIX software that was converted to DOS.....Can't find anything as good as what we had in any other OS. Brent Davis brentd@texasspecialty.com (0 Replies)
Discussion started by: brentpdavis
0 Replies

2. Programming

do you think you are a real c programmer then lets see..

here is a code which sends and receives sms through a serial port. the problem is that its givin segmentation fault. it first sets the file discriptor and the initialises the modem by using AT commands. there are two threads for reading and writing . rest the code is simple you'll get it. user has... (1 Reply)
Discussion started by: harsh_it
1 Replies

3. Shell Programming and Scripting

help a newbie programmer tcl

Prompt please where the error occurred. text.txt obtained by ls-lah> text.txt proc file_to_mas {name_file} { set fileid seek $fileid 0 start global mas set mas(0) 1 for {set i 0} {!} {incr i} { gets... (2 Replies)
Discussion started by: augur_aen
2 Replies

4. Linux

Starting Linux for a Programmer

Hi all I am application Programmer. In my college(2 yrs back) i have learnt Unix i.e commads, shell scripts, Filesystem,I reffered to a book by "Sumitabha Das". I want to learn Linux. But i cant understand where should i start from and which book to refer to. Most of the books these days eg.... (2 Replies)
Discussion started by: FullMetal
2 Replies

5. What is on Your Mind?

A Programmer is .....

https://www.unix.com/picture.php?albumid=112&pictureid=603 (7 Replies)
Discussion started by: Neo
7 Replies

6. Programming

First time programmer needs Help with Makefiles

I am trying to practice to create Makefiles. The goal is to create a makefile such that if a change is made to any of the source code files, the project can be rebuilt by typing make at the command line. I have the following files: ac.cc: has include ac.h and pg.h fr.cc: has main... (8 Replies)
Discussion started by: pintu1228
8 Replies

7. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies
test(1) 						      General Commands Manual							   test(1)

NAME
test, [ - Evaluates conditional expressions SYNOPSIS
test [expression] [[expression]] STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: test: XCU5.0 [: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
The expression to be evaluated as true or false. This expression is constructed from the operators and elements explained in the DESCRIP- TION section. DESCRIPTION
The test command evaluates an expression constructed of functions and operators. If the value of expression is true, test returns an exit value of zero(0); otherwise, it returns FALSE, a nonzero exit value. The test command also returns a nonzero exit value if there are no arguments. The alternate form of the command surrounds expression with brackets ([ ]). When you use this form, you must surround the brackets with spaces. The test Expressions All of the listed functions and operators are separate arguments to test. The following functions are used to construct expression: TRUE if file exists and has read permission. TRUE if file exists and has write permission. TRUE if file exists and has execute permission. TRUE if file exists and is a regular file. TRUE if file exists and is a directory. TRUE if file exists. TRUE if file exists and is a character-special file. TRUE if file exists and is a block-special file. TRUE if file exists and is a named pipe (FIFO). [Tru64 UNIX] TRUE if file exists and is a soft link. Synonym for -L expression. TRUE if file exists and is a soft link. Synonym for -h expression. TRUE if file exists and its set-user ID bit is set. TRUE if file exists and its set-group ID bit is set. [Tru64 UNIX] TRUE if file exists and its sticky bit is set. TRUE if file exists and has a size greater than zero(0). TRUE if the open file with file descriptor number file_descriptor (1 by default) is associated with a terminal device. TRUE if the length of string1 is zero(0). TRUE if the length of string1 is nonzero. TRUE if string1 and string2 are identical. TRUE if string1 and string2 are not identical. TRUE if string1 is not the null string. TRUE if the integers number1 and number2 are algebraically equal. Any of the comparisons -ne, -gt, -ge, -lt, and -le can be used in place of -eq. The listed functions can be combined with the following operators: Unary negation operator. Binary AND operator. Binary OR operator (the -a operator has higher precedence than the -o operator). [Tru64 UNIX] Parentheses for grouping. EXIT STATUS
The following exit values are returned: The test command evaluated expression and its value is TRUE. The test command evaluated expression and is value is FALSE, or there are no arguments. An error occurred. EXAMPLES
To test whether a file exists and is not empty, enter: if test ! -s "$1" then echo $1 does not exist or is empty. fi If the file specified by the first positional parameter to the shell procedure does not exist, this displays an error message. If $1 exists, it displays nothing. There must be a space between -s expression and the file name. The double quotes around $1 ensure that the test will work properly even if the value of $1 is the empty string. If the double quotes are omitted and $1 is the empty string, test displays the error message test: parameter expected. To do a complex compari- son, enter: if [ $# -lt 2 -o ! -s "$1" ] then exit fi If the shell procedure was given fewer than two positional parameters or the file specified by $1 does not exist, then this exits the shell procedure. The special shell variable $# represents the number of positional parameters entered on the command line that started this shell procedure. ENVIRONMENT VARIABLES
The following environment variables affect the execution of test: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for- mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: csh(1), find(1), ksh(1), Bourne shell sh(1b), POSIX shell sh(1p) Standards: standards(5) test(1)
All times are GMT -4. The time now is 03:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy