Sponsored Content
Full Discussion: Add Two Variables
Top Forums Shell Programming and Scripting Add Two Variables Post 20786 by cdin on Friday 3rd of May 2002 03:22:10 PM
Old 05-03-2002
Thanks. I finally found the problem. I was reading a text file and trying to add the value on line 28 to another variable. The problem was the text file was zipped in DOS and then sent to me. So, it contains an extra control code (control-M). Once I delete the control code, bc works great. Really appreciate your help.
 

10 More Discussions You Might Find Interesting

1. Solaris

Add environment variables for all users

hi I need to add environment variables for all users and make them available when they login. I don't know which file to edit. Also these variables should be displayed when "env" command is executed. Please help....which file is common for all users, without editing their specific .profile or... (2 Replies)
Discussion started by: ashish_uiit
2 Replies

2. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

3. Shell Programming and Scripting

bash - add backslash in front of variables w/ spaces

Hello, Im writing a script that works by recursively going into directories with find. But I have some directories that have spaces in them.. so I need to parse the variables to add a backslash before the spaces. Im not exactly sure how how to do this in bash, and honestly I dont think I know... (3 Replies)
Discussion started by: trey85stang
3 Replies

4. Shell Programming and Scripting

[Solved] Find Specific records from file and add totals into variables

Hi Eveyone, I am working on one shell script to find the specific records from data file and add the totals into variables and print them. you can find the sample data file below for more clarification. Sample Data File: PXSTYL00__20090803USA CHCART00__20090803IND... (7 Replies)
Discussion started by: veeru
7 Replies

5. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

6. Shell Programming and Scripting

[Solved] Working with date (add minutes using variables)

Dear all, today I'm scratching my head with a simple (I believe) issue. Working with date is quite simple, so if I Need to add some seconds to current time, I'll use: date --date='+30 seconds' +"%Y-%m-%d %H:%M:%S"But, how to pass the value to add from a variable? I tried the following without... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

7. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

8. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

9. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

10. UNIX for Dummies Questions & Answers

How to pass variables into anothother variables?

Below are three variables, which I want to pass into variable RESULT1 username1=userid poihostname1=dellsys.com port1=8080 How can I pass these variables into below code... RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)
Discussion started by: manohar2013
4 Replies
expr(1B)					     SunOS/BSD Compatibility Package Commands						  expr(1B)

NAME
expr - evaluate arguments as a logical, arithmetic, or string expression SYNOPSIS
/usr/ucb/expr argument... DESCRIPTION
The expr utility evaluates expressions as specified by its arguments. After evaluation, the result is written on the standard output. Each token of the expression is a separate argument, so terms of the expression must be separated by blanks. Characters special to the shell must be escaped. Note: 0 is returned to indicate a zero value, rather than the null string. Strings containing blanks or other special characters should be quoted. Integer-valued arguments may be preceded by a unary minus sign. Internally, integers are treated as 32-bit, two's-complement numbers. The operators and keywords are listed below. Characters that need to be escaped are preceded by `'. The list is in order of increasing precedence, with equal precedence operators grouped within {} symbols. expr | expr Returns the evaluation of the first expr if it is neither NULL nor 0; otherwise, returns the evaluation of the second expr if it is not NULL; otherwise, 0. expr & expr Returns the first expr if neither expr is NULL or 0, otherwise returns 0. expr { =, , , <, <=, != } expr Returns the result of an integer comparison if both arguments are integers, otherwise returns the result of a lexical comparison. expr { +, - } expr Addition or subtraction of integer-valued arguments. expr { , /, % } expr Multiplication, division, or remainder of the integer-valued arguments. string : regular-expression match string regular-expression The two forms of the matching operator above are synonymous. The matching operators : and match compare the first argument with the second argument which must be a regular expression. Regular expression syntax is the same as that of regexp(5), except that all pat- terns are "anchored" (treated as if they begin with ^) and therefore ^ is not a special character, in that context. Normally, the matching operator returns the number of characters matched (0 on failure). Alternatively, the ... pattern symbols can be used to return a portion of the first argument. substr string integer-1 integer-2 Extracts the substring of string starting at position integer-1 and of length integer-2 characters. If integer-1 has a value greater than the length of string, expr returns a null string. If you try to extract more characters than there are in string, expr returns all the remaining characters from string. Beware of using negative values for either integer-1 or integer-2 as expr tends to run forever in these cases. index string character-list Reports the first position in string at which any one of the characters in character-list matches a character in string. length string Returns the length (that is, the number of characters) of string. ( expr ) Parentheses may be used for grouping. EXAMPLES
Example 1 Adding an integer to a shell variable Add 1 to the shell variable a. a='expr $a + 1' Example 2 Returning a path name segment Return the last segment of a path name (that is, the filename part). Watch out for / alone as an argument: expr will take it as the divi- sion operator (see BUGS below). # 'For $a equal to either "/usr/abc/file" or just "file"' expr $a : '.*/ $a Example 3 Using // characters to simplify the expression The addition of the // characters eliminates any ambiguity about the division operator and simplifies the whole expression. # A better representation of example 2. expr //$a : '.*/ Example 4 Returning the value of a variable Returns the number of characters in $VAR. expr $VAR : '.*' EXIT STATUS
expr returns the following exit codes: 0 If the expression is neither NULL nor 0. 1 If the expression is NULL or 0. 2 For invalid expressions. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
sh(1), test(1), attributes(5), regexp(5) DIAGNOSTICS
syntax error for operator/operand errors non-numeric argument if arithmetic is attempted on such a string division by zero if an attempt to divide by zero is made BUGS
After argument processing by the shell, expr cannot tell the difference between an operator and an operand except by the value. If $a is an =, the command: expr $a = '=' looks like: expr = = = as the arguments are passed to expr (and they will all be taken as the = operator). The following works: expr X$a = X= Note: the match, substr, length, and index operators cannot themselves be used as ordinary strings. That is, the expression: example% expr index expurgatorious length syntax error example% generates the `syntax error' message as shown instead of the value 1 as you might expect. SunOS 5.11 6 Jun 2000 expr(1B)
All times are GMT -4. The time now is 07:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy