variable created base on other var value


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers variable created base on other var value
# 1  
Old 05-11-2009
Data variable created base on other var value

hi,
i'm trying to create a script in ksh that will check build logs for errors.
i'm using a variable to hold the grep, somthing like:

grepErr=`echo "grep -i -e ' error ' -e ' errors ' -e 'rror(s)' -e 'Unsatisfied ' -e 'Undefined symbol' -e 'No rule ' -e 'Cannot' -e 'rror:' -e 'Could not find ' -e 'No such file or directory' -e 'Unexpected end of file' -e ' Stop.' -e 'unexpected symbol' -e 'is not a member of'" '$LAST_LOG' "| grep -v 'Warning' > /dev/null"`

This variable is called in a function where the LAST_LOG var will be created.

The problem is that when i'm using grepErr in the function(after LAST_LOG is assigned a value) the value of LAST_log is not substituted.Smilie

i'm new in unix. Can someone please help me with this?

Last edited by lavinia_f; 05-11-2009 at 07:31 AM..
# 2  
Old 05-11-2009
A variable between single quotes is not substituted.
There are a number of bugs in your script. It is not clear to me whether $LAST_LOG is the name of the file you will be searching or part of a string to be ignored. Also whether you want to execute grep now or later?

Anyway, this bit has unbalanced quotes and has protected $LAST_LOG from substitution:
Quote:
'is not a member of'" '$LAST_LOG' "
If $LAST_LOG does not contain space characters, maybe you mean:
Code:
'is not a member of' $LAST_LOG

# 3  
Old 05-11-2009
LAST_LOG is the file where i'm doing grep for errors
in the function i am retriving the name of the last log created and assign it to LAST_LOG:
LAST_LOG=`ls -tr hbuild.log* | tail -1`

after this i call the grep statment
$grepErr

When i delcare grepErr if i use just $LAST_LOG without ', after echo LAST_LOG is replace with "" so in the function the grep statment will fail because it will not know where to search.

the code is somthing like this

#!/bin/ksh

checkLog()
{
...
LAST_LOG=`ls -tr hbuild.log* | tail -1`
if [ $LAST_LOG = ""]
then
echo hbuild file is not present
exit 1
fi
$1
....
}

grepErr=`echo "grep -i -e ' error ' -e ' errors ' -e 'rror(s)' -e 'Unsatisfied ' -e 'Undefined symbol' -e 'No rule ' -e 'Cannot' -e 'rror:' -e 'Could not find ' -e 'No such file or directory' -e 'Unexpected end of file' -e ' Stop.' -e 'unexpected symbol' -e 'is not a member of'" '$LAST_LOG' "| grep -v 'Warning' > /dev/null"`
....
BUILD_RESULT=`checkLog "$grepErr"`
....


Hope it was more clear this time Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to add a variable for the results from the formula of one variable and results of another var

Good morning all, This is the file name in question OD_Orders_2019-02-19.csv I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies

2. Shell Programming and Scripting

How to echo a value of a var stored in another variable?

I'm writing a shell script in AIX and using ksh. I have a scenario where I have a variable A which stores $B. so when i echo "$A" it prints $B But I wish to print value stored in var b ie. \a\dir\res\ I wish to store \a\dir\res\ in a third variable C. later I want to cd into that path :... (1 Reply)
Discussion started by: simpltyansh
1 Replies

3. Programming

Local variable in a C function is not getting created in stack when its compiled with GCC

Hi, I am working in UEFI EDK2 Bios source. We created a platform related new package in the EDK2 source. I find a strange issue with the platform related code we added. When I did source level debugging I noticed the local variable in a C function is not getting created in stack when its... (6 Replies)
Discussion started by: Divya R
6 Replies

4. 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

5. Shell Programming and Scripting

awk: compose regex in variable and then use its contents like $0 ~ var

A question to the awk pundits: I was thinking about composing a regex in a variable and then use its contents like $0 ~ var instead of $0 ~ /r/. Sort of indirection. Did someone run into this? Is it possible at all? (3 Replies)
Discussion started by: RudiC
3 Replies

6. Shell Programming and Scripting

Shell script variable names created dynamically

Hi, I'm trying to use a config file to define frequencies for checking log files. If the config file contains a frequency it will be used else a default value. The format of the config file (and hence the environment variable) is FREQ_log_logname=value A test shell script as below:... (2 Replies)
Discussion started by: u671296
2 Replies

7. Shell Programming and Scripting

Replace a var in sql file with shell script variable

I have a requirement where i have a sql file (filetext.sql). This file contains a variable ss_code. Now in a shell script im trying to replace the variable ss_code with a value contained in the shell script variable MTK_DC..tried the below in the script MTK_DC="mit,cit,bit" OUT=`awk -v... (4 Replies)
Discussion started by: michaelrozar17
4 Replies

8. Shell Programming and Scripting

perl - how can we name a variable base on value of another variable

Hey all, perl - how can we name a variable base on the value of another variable? for example in ksh/bash we do : export c="100" export x`echo $c`=2000 echo $x100 x100=2000 is it possible to do something similar for perl? I already tried many ways but nothing is working. I am... (3 Replies)
Discussion started by: cacm1975
3 Replies

9. UNIX for Dummies Questions & Answers

Files still being created in /var/spool/mmdf/lock/home

Hi all I need help finding a process that is continuing to create files in the above area. There are three sub folder titled addr q.local and msg . I have already found a process called mmdf running and have used the kill command to stop this from running. I have also looked for sendmail or... (12 Replies)
Discussion started by: TeaMaker
12 Replies

10. Shell Programming and Scripting

Passing a variable name to be created within a function

Is it possible to pass a variable name, as a parameter to a function, so it can be created within this function ? Something like this: func_uppercase abcdefgh var_name where the 1st parameter is the string I want to convert and the 2nd is the desired variable name... $2=`echo "$1" |... (2 Replies)
Discussion started by: 435 Gavea
2 Replies
Login or Register to Ask a Question