You could also user typeset to force the variable to be an integer:-
I have noticed a difference in the output from this depending on the OS though.
It seems that AIX (4, 5 and 6) & HP-UX 11 do what I expect, but RHEL (bash & ksh93) computes this to set Var=11
Maybe it's to do with the version of the shell, but AIX 6 has ksh93 available and that works as I expect (value of 13). Something to be tested first. Maybe this would be safer:-
Robin
Last edited by rbatte1; 01-13-2014 at 07:15 AM..
Reason: Grammar
Hi ...
I am trying to calculate the time needed for a command to execute..
but the resulting value is getting as string..
so i am not able to use "expr " command..
please help me to convert the value to integer so that i can proceed with my script..
Regards
esham (1 Reply)
Hi all,
I'm trying to convert a decimal number into an integer number; I'm doing this:
n=`echo |awk '{ print "'"$mem"'"*10}'`
where the variable mem is equal to 3.7
I'd like to obtain 37, but the expression above gives me 30.
Help please!!!!
thx a lot (4 Replies)
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)
Hi everyone,
I would like to know how to convert an integer to a string. for instance if i=1 i would like to creat a variable called constant1. i want to do this in a for loop so for each value of i, i create a new variable such as constant2, constant3,... and so on.
for i in 1 2 3
do ... (1 Reply)
The shell mentioned below will show a warning if the page takes more than 6 seconds to load.
The problem is that myduration variable is not an integer. How do I convert it to integer?
myduration=$(curl http://192.168.50.1/mantisbt/view.php?id=1 -w %{time_total}) > /dev/null ; ] && echo... (3 Replies)
okay so i run an openssl command to get the date of an expired script. Doing so gives me this:
enddate=Jun 26 23:59:59 2012 GMT
Then i cut everything out and just leave the month which is "Jun"
Now the next part of my script is to tell the user if the the certificate is expired or not... (6 Replies)
Dear all,
I have 2 questions.
I have a file with many rows which has date of the format YYYYMMDD.
1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too.
2. After converting the date to... (10 Replies)
I have a function that is supposed to check for user processes and wait for 0 count before exiting the function. I am sure I have more than one issue in my code, but the stumbling block right now is that I am trying to convert the value of my variable from a string to integer.
process_count... (10 Replies)
Hi guys,
I'm new here. I have a problem at work. One of our scripts was eventually having a bug and only detected recently. Here's the issue and background:
Bash Script which calls AWK script
Awk script returns a string as per below (example):var1='00000-123'So, when we convert it, the... (18 Replies)
Hello,
How can we convert date like format 20181004171050 in seconds ?
I can able to convert till date but failing for HHMMSS.
date -d "20181004" "+%s" output as 1538596800 .
But when i add hhmmss it is failing date -d "20181004172000" "+%s" result Invalid date
Kindly guide.
Regards (16 Replies)
Discussion started by: sadique.manzar
16 Replies
LEARN ABOUT OPENSOLARIS
readonly
readonly(1) User Commands readonly(1)NAME
readonly - shell built-in function to protect the value of the given variable from reassignment
SYNOPSIS
sh
readonly [name]...
ksh
**readonly [name [= value]]...
**readonly -p
ksh93
++readonly [-p] [name [= value]]...
DESCRIPTION
sh
The given names are marked readonly and the values of the these names may not be changed by subsequent assignment. If no arguments are
given, a list of all readonly names is printed.
ksh
The given names are marked readonly and these names cannot be changed by subsequent assignment.
When -p is specified, readonly writes to the standard output the names and values of all read-only variables, in the following format:
"readonly %s=%s
", name, value
if name is set, and:
"readonly $s
", name
if name is unset.
The shell formats the output, including the proper use of quoting, so that it is suitable for reinput to the shell as commands that achieve
the same value and readonly attribute-setting results in a shell execution environment in which:
1. Variables with values set at the time they were output do not have the readonly attribute set.
2. Variables that were unset at the time they were output do not have a value at the time at which the saved output is re-input to
the shell.
On this manual page, ksh(1) commands that are preceded by one or two ** (asterisks) are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a
variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera-
tion are not performed.
ksh93
readonly sets the readonly attribute on each of the variables specified by name which prevents their values from being changed. If =value
is specified, the variable name is set to value before the variable is made readonly.
If no names are specified then the names and values of all readonly variables are written to standard output.
readonly is built-in to the shell as a declaration command so that field splitting and pathname expansion are not performed on the argu-
ments. Tilde expansion occurs on value.
-p Causes the output to be in a form of readonly commands that can be used as input to the shell to recreate the current set of readonly
variables.
On this manual page, ksh93(1) commands that are preceded by one or two + symbols are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. They are not valid function names.
5. Words, following a command preceded by ++ that are in the format of a variable assignment, are expanded with the same rules as a
variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name genera-
tion are not performed.
EXIT STATUS
ksh93
The following exit values are returned:
0 Successful completion.
>0 An error occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO ksh(1), ksh93(1), sh(1), typeset(1), attributes(5)SunOS 5.11 2 Nov 2007 readonly(1)