Problem evaluating condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem evaluating condition
# 15  
Old 01-27-2018
It looks like RudiC has identified the source of your problem.

I'm glad that my idea of comparing internal and external invocations of ps showed us that something in your script is affecting the output from ps.

So, try running the command:
Code:
grep COLUMNS scriptname

where scriptname is a pathname to your shell script. And, add:
Code:
echo COLUMNS is $COLUMNS

to the list of things to run inside your function and outside your script to verify that we have identified the problem.

When you obfuscated the output of the uname -n commands, you may have hidden what I was looking for. I don't care about the name of your system, but I do want you to verify that the output from both invocations of uname produced exactly the same output. (We need to be sure that there isn't an ssh or something in your script that is causing some of the code to be executed on a different server!)
# 16  
Old 01-29-2018
Quote:
Originally Posted by RudiC
Hold on, hold on! How do you explain the difference in above outputs: . . . Was the COLUMNS shell variable modified? The second output is clipped at 60 chars... strange
Bingo! The code that called the function looked like this:
Code:
ORACLE_SID=''
PS3='Select  database: '
savcol=$COLUMNS
export COLUMNS=20
#
while [[ $ORACLE_SID = "" ]]; do
  select ORACLE_SID in `egrep -i "product/12" /etc/oratab |grep -v "listener"|\
      awk -F\: '{print $1}'|sort` "All of the above" "None of the above" ; do
    if [[ $ORACLE_SID = "" ]]; then
         echo
         echo "Please enter a valid number.  Retry.";
         echo
    elif [[ $ORACLE_SID = "None of the above" ]]; then
         exit ;
    elif [[ $ORACLE_SID = "All of the above" ]]; then
         get_all_db;
    else {
          get_one_db;
         }
    fi
    break
    done
done
#
unset PS3
export COLUMNS=$savcol

It was based on code from a previous script, where the IF in the loop was just setting values to be acted on after exiting the loop. In this script I decided to create functions to be executed directly from the IF statement, and in that forgot about the need to reset the COLUMNS. I added that statement into the IF construct, just before calling the functions:
Code:
    elif [[ $ORACLE_SID = "All of the above" ]]; then
         export COLUMNS=$savcol;
         get_all_db;
    else {
          export export COLUMNS=$savcol;
          get_one_db;
         }
    fi

and all is working correctly.

Thanks for all the assistance, and patience.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Condition problem

Hi All, Seeking for your assistance on how to condition it correctly. cat file1.txt 290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00 290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00 290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00 1st scenario: if the fourth column contains 888s and 0s it is by... (16 Replies)
Discussion started by: znesotomayor
16 Replies

2. Shell Programming and Scripting

If condition problem

Hi All, I am using below if condition to check whether null is passed as a parameter to the program if or ; then echo "ABC">>$FILE else echo "CDF">>$FILE fi However it is saying me null=null command not found . Please help me with this (9 Replies)
Discussion started by: Hypesslearner
9 Replies

3. Shell Programming and Scripting

Problem in if condition

Hi, below is the script in ksh and i am having issues with if condition. It takes in one argument as input and executes the shell script. The problem is in if condition in shell script. If input is given as 1 it works out well. But if input is given as 2 or something else the script is failing to... (1 Reply)
Discussion started by: abhi_123
1 Replies

4. Shell Programming and Scripting

problem with if condition

Hi, I'm writing a bash script and i have a condition that goes if then break fi but, when i go to run it, i come across this line 10: ' where line 10 is the if I don't know what's going on :( (2 Replies)
Discussion started by: channyboy
2 Replies

5. Shell Programming and Scripting

If condition problem

Hi, I need to use if condition for search a file pattern on a particular location. cd $file_Path if || then do this else do that fi Can someone help me with the if part, how i can put those conditions? make sure format should be *.file* and *.file file is a keyword which i... (5 Replies)
Discussion started by: amit.mathur08
5 Replies

6. Shell Programming and Scripting

if condition not evaluating as expected

Hi all, Thanks in advance for your time. I have a data file like this: 1 7.465753425 2 8.980821918 1 1.717808219 1 6.550684932 0 5.432876712 I wish to write a bash script to check both columns and output a 1 if col1==1 AND col2<3. Otherwise I want to output a 0. In the above... (5 Replies)
Discussion started by: jem8271
5 Replies

7. Shell Programming and Scripting

Problem in using AND OR condition together

a=rhino b=crocodil c=testsc if && "$c" = testsc ] then echo "Test #5 succeeds." else echo "Test #5 fails." fi i need to test or condition before check the output with AND condition. ur help is much appreciated... (11 Replies)
Discussion started by: gokulraj23
11 Replies

8. Shell Programming and Scripting

problem in if then else condition

Hi , I am trying the following simple script . But it is always giving 1 output. Dont know why #!/bin/sh find . -name "a.log" if ; then echo "1" else echo "0" fi Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
Discussion started by: himvat
26 Replies

9. Shell Programming and Scripting

problem in if condition

hi, actully i need the belp for the below. host_list=" Host1 host2 host3 host4 " n=`hostname` i need to put the condition like the below if n is among the host mention in the host_list if then #some stugg else # some other stuff fi (1 Reply)
Discussion started by: mail2sant
1 Replies

10. Shell Programming and Scripting

problem with if condition

hi, :) pls consider the following if statement if //g') ] then ........ else ....... when i execute the script i am getting the following error '(' unexpected I am not able to find the mistake. could anybody tell where i did mistake. cheers RRK (13 Replies)
Discussion started by: ravi raj kumar
13 Replies
Login or Register to Ask a Question