01-12-2010
Quote:
Originally Posted by
tlarkin
Thanks for your reply, but still got a few questions...
According to this document, which I have used to teach myself shell programming, [[ and [ have different abilities in bash.
Yes, BASH has many extensions on the standard shell. But you can't depend on those extensions anywhere else.
As for numerical and string equality being identical, well -- given the same number base and no leading zeroes or extraneous sign symbols, a string comparison is no different than a numerical comparison. I've tried various things to trip them up, things like comparing positive and negative zero... it always acts just like a string comparison whether its one or two equals.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Say for example I have a list of numbers..
5
10
13
48
1
could I use grep to show only those numbers that are above 10? For various reasons I can only use grep... not awk or sed etc. (7 Replies)
Discussion started by: Uss_Defiant
7 Replies
2. Shell Programming and Scripting
I have two files.And a sort of matrix analysis.
Both files have a string followed by two numbers:
File 1:
A 2 7
B 3 11
C 5 10
......
File 2:
X 1 10
Y 3 5
Z 5 9
What I'd like to do is for each set of numbers in the second file indicate if the first or second number (or both) in... (7 Replies)
Discussion started by: dcfargo
7 Replies
3. UNIX for Dummies Questions & Answers
Hi guys,
Im trying to figure out what is the difference between using a | and the command xargs ... examples of usage:
1) ls * | wc -w => this gives you the number of files in the current directory including all subdirectories
2) find . “*.log” | xargs grep ERROR => this gives... (6 Replies)
Discussion started by: avidrunner
6 Replies
4. Shell Programming and Scripting
Can somebody tell me the difference between double brackets and single
brackets, when doing a test.
I have always been acustomed to using single brackets and have not
encountered any issues to date. Why would somebody use double brackets.
Ie
if ]
vs
if
Thanks to... (2 Replies)
Discussion started by: BeefStu
2 Replies
5. Shell Programming and Scripting
Can someone please tell me what is wrong with this stings comparison?
#!/bin/sh
#set -xv
set -u
VAR=$(ping -c 5 -w 10 google.com | grep icmp_req=5 | awk '{print $6}')
echo I like cookies
echo $VAR
if "$VAR" == 'icmp_req=5'
then
echo You Rock
else
echo You Stink
fiThis is the error.... (6 Replies)
Discussion started by: cokedude
6 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I want to perform a simple date comparisons, i.e. select all files modified after a certain date (say 12-feb-2011)
I do not have the option of creating a file and using find's -newer option.
Any simple way to do this? I can do this by reading the stat command's output and comparing... (10 Replies)
Discussion started by: jawsnnn
10 Replies
7. UNIX for Dummies Questions & Answers
I'd love to get help on this one please. Ok so say I have a file called README with lines such as this:
index:index.html
required:file1.1:file2.1:file3.1
I'm having trouble with writing an if statement that compares the items in a list with a file inside README, what I imagine in my head... (7 Replies)
Discussion started by: mistsong1
7 Replies
8. Shell Programming and Scripting
Hi,
I have 25 groups and I need to perform all possible pairwise compariosns between them using the formula n(n-1)/2. SO in my case it will be 25(25-1)/2 which is equal to 300 comparisons.
my 25 groups are
FG1 FG2 FG3 FG4 FG5
NT5E CD44 CD44 CD44 AXL
ADAM19 CCDC80 L1CAM L1CAM CD44... (1 Reply)
Discussion started by: Diya123
1 Replies
9. Shell Programming and Scripting
Hi all,
I want to compare two files based on column value
Kindly help me
a.txt
123,ABCD
456,DEF
789,SDF
b.txt
123,KJI
456,LMN
321,MJK
678,KOL
Output file should be like
Common on both files
c.txt
123,ABCD,KJI (8 Replies)
Discussion started by: aaysa123
8 Replies
10. Shell Programming and Scripting
Here is the sample code:
str1="abccccc"
str2="abc?"
if ]; then
echo "same string"
else
echo "different string"
fi
Given that ? implies 0 or 1 match of preceding character, I was expecting the output to be "different string", but I am seeing "same string".
Am I not using the... (3 Replies)
Discussion started by: Rameshck
3 Replies
proc(n) Tcl Built-In Commands proc(n)
__________________________________________________________________________________________________________________________________________________
NAME
proc - Create a Tcl procedure
SYNOPSIS
proc name args body
_________________________________________________________________
DESCRIPTION
The proc command creates a new Tcl procedure named name, replacing any existing command or procedure there may have been by that name.
Whenever the new command is invoked, the contents of body will be executed by the Tcl interpreter. Normally, name is unqualified (does not
include the names of any containing namespaces), and the new procedure is created in the current namespace. If name includes any namespace
qualifiers, the procedure is created in the specified namespace. Args specifies the formal arguments to the procedure. It consists of a
list, possibly empty, each of whose elements specifies one argument. Each argument specifier is also a list with either one or two fields.
If there is only a single field in the specifier then it is the name of the argument; if there are two fields, then the first is the argu-
ment name and the second is its default value. Arguments with default values that are followed by non-defaulted arguments become required
arguments. In 8.6 this will be considered an error.
When name is invoked a local variable will be created for each of the formal arguments to the procedure; its value will be the value of
corresponding argument in the invoking command or the argument's default value. Actual arguments are assigned to formal arguments strictly
in order. Arguments with default values need not be specified in a procedure invocation. However, there must be enough actual arguments
for all the formal arguments that do not have defaults, and there must not be any extra actual arguments. Arguments with default values
that are followed by non-defaulted arguments become required arguments (in 8.6 it will be considered an error). There is one special case
to permit procedures with variable numbers of arguments. If the last formal argument has the name args, then a call to the procedure may
contain more actual arguments than the procedure has formals. In this case, all of the actual arguments starting at the one that would be
assigned to args are combined into a list (as if the list command had been used); this combined value is assigned to the local variable
args.
When body is being executed, variable names normally refer to local variables, which are created automatically when referenced and deleted
when the procedure returns. One local variable is automatically created for each of the procedure's arguments. Other variables can only
be accessed by invoking one of the global, variable, upvar or namespace upvar commands.
The proc command returns an empty string. When a procedure is invoked, the procedure's return value is the value specified in a return
command. If the procedure does not execute an explicit return, then its return value is the value of the last command executed in the pro-
cedure's body. If an error occurs while executing the procedure body, then the procedure-as-a-whole will return that same error.
EXAMPLES
This is a procedure that accepts arbitrarily many arguments and prints them out, one by one.
proc printArguments args {
foreach arg $args {
puts $arg
}
}
This procedure is a bit like the incr command, except it multiplies the contents of the named variable by the value, which defaults to 2:
proc mult {varName {multiplier 2}} {
upvar 1 $varName var
set var [expr {$var * $multiplier}]
}
SEE ALSO
info(n), unknown(n)
KEYWORDS
argument, procedure
Tcl proc(n)