Help copy variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help copy variable
# 8  
Old 08-24-2014
Thanks a lot Scrutinizer
You really saved me
this is really great help
Thanks a lot Smilie
# 9  
Old 08-24-2014
This includes extra lines to show what it is doing...
Code:
#!/bin/bash
# getvar.sh
# *** Create a file to work with called /tmp/var, this is from your latest reply...
echo '//*********************************\\
Build   : xxxxxxxxxxxx
Date    : Aug 24 2014
Host    : linuxUser
PID      : 3004 
xVal     : 34.0
yVal     : 101.92
:
:
xVal = 10
yVal = 20
zVal = 30' > /tmp/var
# Allocate two variables for this DEMO.
text=""
value=0
# Working code start...
while read text
do
	# (This assumes that there is a fixed width of 7 characters before the value required.)
	# Compare the first 7 characters with "xVal = " and if it exists then......
	if [ "${text:0:7}" == "xVal = " ]
	then
		# ......allocate that __number__ to variable 'value'.
		value=${text:7}
		# Once it has been detected break from the 'while' loop.
		break
	fi
# Reading from the generated file from *** above...
done < /tmp/var
# Working code end...
# The value and number of characters ensuring no leading whitespaces.
echo "The variable 'value' is $value, and the number of characters are ${#value}..."
# Exit with a return code of zero.
exit 0

Results:-
Code:
Last login: Sun Aug 24 21:19:18 on ttys000
AMIGA:barrywalker~> ./getvar.sh
The variable 'value' is 10, and the number of characters are 2...
AMIGA:barrywalker~> _

This User Gave Thanks to wisecracker For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy script output to a variable using same script?

I'm trying to copy script output and use it in this same script as a variable, and call the variable when script is compiled. The script is below. #!/bin/bash output=$(script) while read line; do if ]; then grep "$line" logfile.txt # Create text file echo "From: IT ... (4 Replies)
Discussion started by: SysAdminRialto
4 Replies

2. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

3. Shell Programming and Scripting

Shell Script to Search for a particular String and copy the timestamp to a variable

Hi, We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below: Process Beginning - 08-26-2010-23.41.47 DB2 CONNECTION SUCCESSFUL! Ready to process and load file: FILENAME # of... (2 Replies)
Discussion started by: Praveenkulkarni
2 Replies

4. Shell Programming and Scripting

Making script show command (e.g. copy) being executed and variable substitution?

When script is running you only see when some of the commands are not successfull. Is there a way to see which command are executed and to show the substitution of variables as every line is executed ? (3 Replies)
Discussion started by: gr0124
3 Replies

5. Shell Programming and Scripting

Parse file and copy value to variable in sh script.

Hi, I need to parse a simple text file like below and store the word that starts with BR* to a variable say $BRno. I need to do this in sh script. NOTE: the length of the numbers following BR is not constant (eg: it could be BR1234 or BR22233). And there is only 1 BRxxxxx in a file at a given... (6 Replies)
Discussion started by: script2010
6 Replies

6. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

7. Shell Programming and Scripting

Copy part of a variable

Hi, i was using a input file to get the last line of the file.But now i have stored the values from the file to a variable and want the last line from the variable . Slightly confused on how to extract that data from the variable. previous code, cat input.txt <TIME>00:15:48</TIME>... (2 Replies)
Discussion started by: Shellslave
2 Replies

8. UNIX for Dummies Questions & Answers

What is in-core copy and disk-copy of i-node table?

I have found a question from the exercises of my study mat. The question is "Why are there a in-core copy and a disk-copy of i-node block and super block?" If any one know the proper answer then please send me..... (1 Reply)
Discussion started by: dearanik
1 Replies

9. Shell Programming and Scripting

Representing dir path for copy through env variable

Hello , i am on linux, and im trying to figure out why my cp command cant copy one file. I am trying to use variable in which i stored path to location where is file i wish to copy. $ echo $ORA_ALERT_LOG /u01/app/oracle/diag/rdbms/ring11/ring11/trace $ $ $ pwd /home/oracle $ cp -p... (2 Replies)
Discussion started by: tonijel
2 Replies
Login or Register to Ask a Question