Get variables from expression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get variables from expression
# 8  
Old 05-14-2014
Quote:
Originally Posted by sea
Homework?
it's projectwork
# 9  
Old 05-14-2014
Is there a reason that you have to use expr? Can I assume that you have read the manual page for expr and digested it? It's not a nice way to users to write rules.

It seems a bit of a limitation, however you can still use the framework I suggested you can code the following in you users' personal file:-
Code:
RBATTE1> cat ~/my_variables
UsrAppNO=`expr UsrCustGBLNo \*2 + UsrCustRegNo +99`

It's messy and brackets are a problem. Notice how the multiplier * has to be coded as \*, as would the divider / needing to be \/

For numeric assignments, you might be better with bc like this:-
Code:
UsrAppNO=`echo UsrCustGBLNo \*2 + UsrCustRegNo +99 | bc`

.... but again it's not great.


If you are allowing them to do this, can you not set the rules? If the only value they really need to put in individually is the UsrCustRegNo, then just have this in the users' my_variables file:-
Code:
UsrCustNo=50

.... and then do the calculation in your main script. If it is a common calculation that several scripts use, then you could have a common bit of code called in the same way in my suggested framework from before, by just adding the file name in after where the user definitions are called.



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SHELL: UNIX : Ls regular expression not working when used with variables

If i do below command in unix prompt which static values (ie 27..97), it is working fine and gives desired output >ls -d $WORKDIR/batch/somefilename_{27..97}.* 2>/dev/null somefilename_27.sometxt somefilename_28.sometxt somefilename_29.sometxt .. somefilename_97.sometxt But if i want... (2 Replies)
Discussion started by: haiderali
2 Replies

2. Shell Programming and Scripting

Why Relational Expression is Writing to a Expression?

Hello All, Not sure why this is happening... When the following If Statement is evaluated for some reason it is creating a file in the CWD called '0'. I've seen this happen before, just not in an If Statement... CODE: if then DIR_NAME="$1" DIR_SIZE=0 STATUS="" else... (3 Replies)
Discussion started by: mrm5102
3 Replies

3. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

4. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

5. Shell Programming and Scripting

awk variables in regex expression ?

Hello, Could someone explain why this one returns nothing: $ x=/jon/ $ echo jon | awk -v xa=$x '$1~xa {print}' $ while the following works fine: $ x=jon $ echo jon | awk -v xa=$x '$1==xa {print}' $ jon and the following works fine: $ echo jon | awk '$1~/jon/ {print}' $ jon ... (3 Replies)
Discussion started by: vilius
3 Replies

6. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

7. Shell Programming and Scripting

Assigning expression value to tcsh variables

Hi All, I have a tcsh script as: #!/usr/bin/csh -x set packsName=$(awk -F'' '/^execute.*=true/{print $2}' ExecutePacks.config) for var in $packsName do echo "printed $var" done I want to assign the value which is returned by awk function to the variable called packsName. How do I... (2 Replies)
Discussion started by: AB10
2 Replies

8. Shell Programming and Scripting

Need help with arithmetic expression using variables

Hi, I am trying to do a percentage calculation in a Bourne shell script. The following works fine, but when I try to subsitute the values 153824 and 246000 for variables (e.g. used and limit), I get errors. calc() { awk 'BEGIN {OFMT="%f"; print '"$*"'; exit}' } calc '(153824 /... (3 Replies)
Discussion started by: shorehil
3 Replies

9. Programming

error: initializer expression list treated as compound expression

I had seen this error for the first time ..... error: initializer expression list treated as compound expression please help.... (12 Replies)
Discussion started by: arunchaudhary19
12 Replies

10. Shell Programming and Scripting

Regular Expression + Aritmetical Expression

Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant. THX! (2 Replies)
Discussion started by: Z0mby
2 Replies
Login or Register to Ask a Question