scope of a Variable inside shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scope of a Variable inside shell script
# 1  
Old 11-02-2009
PHP scope of a Variable inside shell script

hi all,

i'm using the following script,
Code:
Status=1
Function_do ()
{
while read line;
do
    if [ ` echo $line | grep 'symbol not found:' | wc -l` -eq 1 ]; then
        #echo $line
        if [ ! `echo $line | grep 'kxdfhei1' | wc -l ` -eq 1  -o  ! `echo $line | grep 'main' | wc -l ` -eq 1 ]; then
            Status=0
            echo " LINKINK ERROR "
        fi
    fi
done < ldd.log
}

Function_do
echo " Status = $Status "

OUTPUT:
Code:
LINKINK ERROR
Status = 1

What happen to the value of Status=0 that i set inside If condition? What happens if use while? the same script if i use for loop it is giving proper output.. status=0. I'm not able to understand the logic behind it. Can any one help me in this?


Regards,
Vijay

Last edited by pludi; 11-02-2009 at 03:45 AM.. Reason: code tags, please...
# 2  
Old 11-02-2009
Hi,

I have tried but , I am getting below output.

Code:
 Before calling Status = 1
 LINKINK ERROR
 After Calling Status = 0

# 3  
Old 11-02-2009
when i run the above script as sh test.sh its not giving the proper output. But when i rename it to test.ksh and run as ksh test.ksh it is woking. I dont know what is the difference. I'm using Sun Solaris...
# 4  
Old 11-02-2009
If it works fine with ksh, why not sticking with it ?

I guess the issue is /bin/sh running the while loop in a subshell because of the input redirection.
# 5  
Old 11-02-2009
Hi,

It is the behaviour of the borune shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a Boolean variable which succeed and failed inside the if loop in shell script ?

I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger. if ] then echo "Only satisfied variable with value" ... (3 Replies)
Discussion started by: prince1987
3 Replies

2. Shell Programming and Scripting

The Start Of A Simple Audio Scope Shell Script...

This is a DEMO shell script to generate a simple graticule and plot inside it... Apologies for any typos... it is another building block along with my other two shell uploads recently to start a semi_serious project of an Terminal_AudioScope... The fist upload I posted recently was to show... (83 Replies)
Discussion started by: wisecracker
83 Replies

3. Shell Programming and Scripting

Search the shell variable inside awk

Hai, I need to search a variable inside a file using awk in AIX. for ex: file.txt one two three four five i need to get the lines with two awk '/two/ {print}' file.txt But i need to change the two as a variable since it would be changed on runtime..i tried like below..nothing give... (3 Replies)
Discussion started by: jesu
3 Replies

4. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

5. Shell Programming and Scripting

Bourne Shell - Problem with while loop variable scope.

Hello I am having issues with a script I'm working on developing on a Solaris machine. The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today. Here is my while loop: last $user | grep -v 'sshd'... (7 Replies)
Discussion started by: DaveRich
7 Replies

6. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

7. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

8. Shell Programming and Scripting

problem with shell variable's scope

Hi, I am stuck while developing a shell sub-routine which checks the log file for "success" or "failure". The subroutine reads the log file and checks for key word "success", if found it set the variable (found=1). It returns success or failure based on this variable. My problem is, I can... (2 Replies)
Discussion started by: cjjoy
2 Replies

9. Shell Programming and Scripting

Changing value of a variable inside a shell script

I have a continous polling happening inside a shell script on AIX. This actually calls a PL/SQL block. Is there a way I can set up a variable or pass an interrupt to end the script gracefully. I cant read from the config once the job starts running. Ideally I should change value of a variable and... (1 Reply)
Discussion started by: kshyju
1 Replies

10. Shell Programming and Scripting

replacing a number with random variable inside shell script

Hi All. I need help for the below logic. I ve a file like following input file: NopTX(5) // should be remain same as input ----Nop(@100); //1 Nop(90); //2 --Nop(80); //3 @Nop(70); //4 --@Nop(60); //5 @Nop@(@50); //6 --Nop@( 40); ... (3 Replies)
Discussion started by: user_prady
3 Replies
Login or Register to Ask a Question