06-10-2008
Subtracting an Integer from a Variable
Hello,
I am in following situation.-
COUNT=`ls -l | wc -l`
echo $COUNT
---> 26
NO_OF_FILES=$COUNT-1
echo $NO_OF_FILES
---> 26-1
Here, I want the output to be 25. How could I do this. It seems simple, but I am not getting it. Please help me.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
I have an expression using grep and nawk that captures the ID number of a given Unix process. It gets printed to screen but I don't know how to declare a variable to this returned value!
For example,
ps -ef|grep $project | grep -v grep | nawk '{print $2}'
This returns my number. How... (2 Replies)
Discussion started by: babariba
2 Replies
2. Programming
I have a class with an integer pointer, which I have not initialized to NULL in the constructor. For example:
class myclass
{
private:
char * name;
int *site;
}
myclass:: myclass(....)
: name(NULL)
{
.....
}
other member function “delete “ the variable before... (2 Replies)
Discussion started by: sureshreddi_ps
2 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I am passing a variable to a unix function.
However when I try to assign the value to another variable like
typeset -i I_CACHE_VAL=$2
Is this because of String to Integer conversion?
I get an error.
Please help me with thsi.
Thanks (2 Replies)
Discussion started by: neeto
2 Replies
4. Shell Programming and Scripting
Hi !
I'm looking for a way to transform certain floating point numbers in a one-line, variable length file to integers.
I can do this in a crude way with sed :
sed -e 's/0\.\(\):/\1:/g' -e 's/0\.0\(\):/\1:/g' -e 's/1\.000:/100:/g' myfile ... but this doesn't handle the rounding correctly.
... (3 Replies)
Discussion started by: jossojjos
3 Replies
5. Shell Programming and Scripting
I would like to know the maximum integer that a variable can hold. Actually one of my variable holds value 2231599773 and hence the script fails to process it.Do we have any other data type or options available to handle this long integers? (9 Replies)
Discussion started by: michaelrozar17
9 Replies
6. Shell Programming and Scripting
I read 3 variables from from Inputfile.txt the third one "startnumber" is a number when i compare it with 9 ($startnumber -le 9) it give's me a "unary operator expected", i know that -le is for number comparison. What i need is to convert $startnumber to integer (i have try to do it with expr but... (8 Replies)
Discussion started by: marios
8 Replies
7. Solaris
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 (10 Replies)
Discussion started by: shatztal
10 Replies
8. Shell Programming and Scripting
Legends,
Please help me in , how do i subtract the variable values listed like below.
the first value of orig should be subtracted from first value of prev and so on.
san> echo $orig
346 316 340 239 410 107 291 139 128 230 167 147 159 159 172 116 110 260 177 0 177 169 168 186 165 366 195... (15 Replies)
Discussion started by: sdosanjh
15 Replies
9. Shell Programming and Scripting
Hi Guys,
i guess there is a several ways to grub the strings from date and time
like THISMONTH='/bin/date +%m'
but the hard part is to add or sub that string to a variable
i tried to use let command
TWOMONTHSAGO=$THISMONTH
declare -i TWOMONTHSAGO
let TWOMONTHSAGO-=2
but there... (1 Reply)
Discussion started by: CyR0iz4l1v3
1 Replies
10. UNIX for Beginners Questions & Answers
Hi Folks -
Linux Version = Linux 2.6.39-400.128.17.el5uek x86_64
I have a process that determines the start and end load periods for an Oracle data load process.
The variables used are as follows follows:
They are populated like such:
However, the load requires the month to be the... (11 Replies)
Discussion started by: SIMMS7400
11 Replies
SG_SYNC(8) SG3_UTILS SG_SYNC(8)
NAME
sg_sync - send the scsi command synchronize cache
SYNOPSIS
sg_sync [--count=COUNT] [--group=GROUP] [--help] [--immed] [--lba=LBA] [--sync-nv] [--verbose] [--version] DEVICE
DESCRIPTION
Send SYNCHRONIZE CACHE (10) command to DEVICE. This command is defined for SCSI block devices (see SBC-2). If successful this command makes
sure that any blocks whose latest versions are held in (volatile) cache are written to (also termed as "synchronized with") the medium. If
the --sync-nv option is given and the device has a non-volatile cache then any blocks whose latest versions are held in volatile cache are
written to non-volatile cache.
If the LBA and COUNT arguments are both zero (their defaults) then all blocks in the cache are synchronized. If LBA is greater than zero
while COUNT is zero then blocks in the cache whose addresses are from and including LBA to the highest lba on the device are synchronized.
If both LBA and COUNT are non zero then blocks in the cache whose addresses lie in the range LBA to LBA+COUNT-1 inclusive are synchronized
with the medium.
OPTIONS
Arguments to long options are mandatory for short options as well.
-c, --count=COUNT
where COUNT is the number of blocks to synchronize from and including LBA. Default value is 0. When 0 then all blocks in the
(volatile) cache from and including LBA argument to the highest block address are synchronized.
-g, --group=GROUP
where GROUP is the group number which can be between 0 and 31 inclusive. The default value is 0 . Group numbers are used to segre-
gate data collected within the device. This is a new feature in SBC-2 and can probably be ignored for the time being.
-h, --help
output the usage message then exit.
-i, --immed
sets the IMMED bit in the SYNCHRONIZE CACHE command. This instructs the device, if the format of the command is acceptable, to
return a GOOD status immediately rather than wait for the blocks in the (volatile) cache to be synchronized with (i.e. written to)
the medium (or the non-volatile cache).
-l, --lba=LBA
where LBA is the lowest logical block address in the (volatile) cache to synchronize to the medium (or the non-volatile cache).
Default value is 0 .
-s, --sync-nv
synchronize the (volatile) cache with the non-volatile cache. Without this option (or if there is no non-volatile cache in the
device) the synchronization is with the medium.
-v, --verbose
increase the level of verbosity, (i.e. debug output).
-V, --version
print the version string and then exit.
NOTES
The COUNT, GROUP and LBA arguments may be followed by one of these multiplicative suffixes: c C *1; w W *2; b B *512; k K KiB *1,024; KB
*1,000; m M MiB *1,048,576; MB *1,000,000 . This pattern continues for "G", "T" and "P". Also a suffix of the form "x<n>" multiplies the
leading number by <n>. The "T" and "P" suffixes can only be used for COUNT and LBA.
Alternatively numerical values can be given in hexadecimal preceded by either "0x" or "0X" (or with a trailing "h" or "H"). When hex num-
bers are given, multipliers cannot be used.
EXIT STATUS
The exit status of sg_sync is 0 when it is successful. Otherwise see the sg3_utils(8) man page.
AUTHORS
Written by Douglas Gilbert.
REPORTING BUGS
Report bugs to <dgilbert at interlog dot com>.
COPYRIGHT
Copyright (C) 2004-2006 Douglas Gilbert
This software is distributed under a FreeBSD license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR-
POSE.
SEE ALSO
sg_start(sg3_utils)
sg3_utils-1.22 December 2006 SG_SYNC(8)