Math with user variables


 
Thread Tools Search this Thread
Top Forums Programming Math with user variables
# 1  
Old 02-07-2007
Tools Math with user variables

Hi everybody:
I have a problem about use variables. I 've created this variable:

var=`wc -l file.txt | cut -c 1-2`;
n_var="$var"-1 ;
echo $n_var;


In my case var is 8.
When echo shows $n_var does not appear as I want. The question is how can I subtract, this is operate, to my variable.
Thanks in advance and cheers. Smilie
tonet
# 2  
Old 02-07-2007
This is not the right umbrella to post this question !!!


something like this,

Code:
var=`wc -l < filename`
echo $var
var=$(($var - 1))
echo $var

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX $USER and $LOGNAME environment variables

I have some comments about a previously closed topic whose name is the same as above Omitted from the discussion was the situation with a "sudo command or sudo within a script". There is an inconsistency between systems. On some systems $LOGNAME is invariant, on others, on RedHat sudo... (3 Replies)
Discussion started by: lsatenstein
3 Replies

2. UNIX for Dummies Questions & Answers

Set env variables for user

Hi , I have installed oracle in Solaris machine and unable to set the env variable. I tried to put the env variable in .dtprofile file but didn't help. So everytime I login in need to run the command and export the variable. Kindly suggest where I am doing wrong.Pls excuse as I am not too... (2 Replies)
Discussion started by: Rossdba
2 Replies

3. Shell Programming and Scripting

Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example $GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies

4. Shell Programming and Scripting

Ask variables to user by script

Hi. Is there any way of in a script ask the user something and with the user answer retreave a internal result that uses the variable that the user had introduced? Thanks (3 Replies)
Discussion started by: whity
3 Replies

5. UNIX for Dummies Questions & Answers

Variables and math in Old skool Bourne Shell

Hey everybody, I've been searching google and these forums and have found some solutions to the issues I've been having today within the OLD Bourne Shell. I am following chapter 6 of the Guide to Unix using Linux 4th Edition. I am working on some basic calculations with variables in the BASH... (3 Replies)
Discussion started by: mr.rhtuner
3 Replies

6. Shell Programming and Scripting

Unix $USER and $LOGNAME environment variables

Hi, I am wondering what is the difference between the USER and LOGNAME environment variables, and under what situations would they be different? I am using Ubuntu 8.04 32-bit and I do not have 'login' command to test it. (7 Replies)
Discussion started by: royalibrahim
7 Replies

7. Shell Programming and Scripting

Manipulating env variables for user apache?

So that they can be used in a cgi script? How best to do this? Thanks ---------- Post updated at 06:24 PM ---------- Previous update was at 02:38 AM ---------- Anyone that can help me with this? Basically I want to add an environment variable that will be visible to the cgi scripts when I... (0 Replies)
Discussion started by: stevenswj
0 Replies

8. Shell Programming and Scripting

Validate Variables insert from user

Hi Can you help me validate 2 variables?The first is an input date from the user and should be like this (yyyy-mm-dd). The second variable is an input time from the user and should be like this(hh:mm).When the input is wrong i want to give the chance to the user to insert again the date or time... (8 Replies)
Discussion started by: DDoS
8 Replies

9. Shell Programming and Scripting

awk printf for user defined variables

I am working on a SunFire 480 - uname -a gives: SunOS bsmdb02 5.9 Generic_112233-08 sun4u sparc SUNW,Sun-Fire-480R I am tyring to sum up the total size of all the directories for each running database using awk: #!/usr/bin/ksh for Database in `ps -efl | grep "ora_pmon" | grep -v grep |... (1 Reply)
Discussion started by: jabberwocky
1 Replies

10. UNIX for Advanced & Expert Users

Expanding Variables in User Input

If have var='$variable' how can I expand $variable. I have tried many thing like duble quotes/braces etc, but nothing worked. I need the solution ASAP. (2 Replies)
Discussion started by: Bsk
2 Replies
Login or Register to Ask a Question