Visit Our UNIX and Linux User Community

Retaining value in var for flag.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retaining value in var for flag.
# 1  
Old 05-28-2005
Retaining value in var for flag.

I have problem like this :

while loop

1 var=some expression

2 if [ $var -ne $oldVar ] then
3 Do something
4 oldVar=$var
5 fi

6 done

Then, I am facing error at line number 2, mentioning invalid argument. Can anyone please help me for, How to retain value in oldVar?
# 2  
Old 05-28-2005
if [ "$var" -ne "$oldVar" ]; then
# 3  
Old 05-28-2005
Then, I am facing error at line number 2, mentioning invalid argument. Can anyone please help me for, How to retain value in oldVar?
Is var and oldvar holding integers ??
# 4  
Old 05-31-2005
Yes, var & oldvar hold integer value.
# 5  
Old 05-31-2005
To be safe, oldvar should be defined prior to the loop.

Previous Thread | Next Thread
Test Your Knowledge in Computers #603
Difficulty: Medium
MySQL 8.0 does not maintain information about password history so you cannot enabling restrictions on reuse of previous passwords.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retaining value outside loop

Hi, I m new to shell scripting. I did some research and understand that unix treats while and other loops as new shell and hence the variable loose its value outside of the loop. I found solution for integer variable but in mycase this is a string variable. here variable loc is a... (6 Replies)
Discussion started by: knowyrtech
6 Replies

2. Shell Programming and Scripting

Transfer the logs being thrown into /var/log/messages into another file example /var/log/volumelog

I have been searching and reading about syslog. I would like to know how to Transfer the logs being thrown into /var/log/messages into another file example /var/log/volumelog. tail -f /var/log/messages dblogger: msg_to_dbrow: no logtype using missing dblogger: msg_to_dbrow_str: val ==... (2 Replies)
Discussion started by: kenshinhimura
2 Replies

3. Shell Programming and Scripting

Csh , how to set var value into new var, in short string concatenation

i try to find way to make string concatenation in csh ( sorry this is what i have ) so i found out i can't do : set string_buff = "" foreach line("`cat $source_dir/$f`") $string_buff = string_buff $line end how can i do string concatenation? (1 Reply)
Discussion started by: umen
1 Replies

4. Shell Programming and Scripting

Retaining whitespaces...

There's an input file(input.txt) which has the following details : CBA BA <Please note the second record has a LEADING WHITESPACE which is VALID> I am using the following code to read the content of the said file line by line: while read p ; do echo "$p" done < input.txt This is the... (1 Reply)
Discussion started by: kumarjt
1 Replies

5. Shell Programming and Scripting

help in retaining leading zero

Hello. I'm trying to add multiple numbers with varying length and with leading zeroes in it. However, I'm getting the sum (totalHashAccountNumber) without the leading zeroes in it. How do I retain the leading zeroes? Please pardon the lengthy code.. I'm getting the hash account number from 2... (2 Replies)
Discussion started by: udelalv
2 Replies

6. Solaris

Difference between /var/log/syslog and /var/adm/messages

Hi, Is the contents in /var/log/syslog and /var/adm/messages are same?? Regards (3 Replies)
Discussion started by: vks47
3 Replies

7. Solaris

/var/adm & /var/sadm

what is the difference between tha /var/adm and /var/sadm files in solaris 10 Os please can any one respond quickly thanking you (2 Replies)
Discussion started by: wkbn86
2 Replies

8. Shell Programming and Scripting

Variable value not retaining outside function

Hi All, As per my understanding, value of variable is retained outside function. But the value of array myarrayDriver is not retained outside function. Could you please tell the reason for the same.. code: readingConfigFile() { search_keyword="$1" i=0 for pointer in $(cat... (7 Replies)
Discussion started by: ajincoep
7 Replies

9. Solaris

diff b/w /var/log/syslog and /var/adm/messages

hi sirs can u tell the difference between /var/log/syslogs and /var/adm/messages in my working place i am having two servers. in one servers messages file is empty and syslog file is going on increasing.. and in another servers message file is going on increasing but syslog file is... (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

10. Shell Programming and Scripting

variable not retaining value

Bourne shell Solaris I'm trying to set a flag to perform an action only when data is found. So I initialize the flag with: X=0 Then I read the data: if ; then while read a b c do X=1 done < ${inputFile} fi The problem is that X will be set to 1 inside the while loop but when... (5 Replies)
Discussion started by: gillbates
5 Replies

Featured Tech Videos