Unable to get the accurate value of shell variable set inside a pipe

RajSanpui

I am trying to set a variable, based on the execution result of a MySQL statement like this:

    errorOut=0
    mysql -uroot -pinsite3 -rN --execute "select file_system_id from ifm.PartitionTable where physical_partition='$partName'" | while read myVal
    do
      echo "myVal = $myVal"
      if [ $myVal -eq $fsId ];then
        errorOut=1
        echo "Found equal: errorOut = $errorOut"
      fi
    done
    echo "Outside loop: errOut = $errorOut"


Here is the output:
myVal = 1
myVal = 2
Found equal: errorOut = 1
Outside loop: errOut = 0

As you can see, due to pipe I am unable to get the value of the variable outside the loop (as the variable inside pipe, is basically set forking a different process)

Is there any way i can extract the actual value outside the loop?

Yannoff

What if you use a for...in instead of read, like this? :

errorOut=0
for myVal in $(mysql -uroot -pinsite3 -rN --execute "select file_system_id from ifm.PartitionTable where physical_partition='$partName'")
do
  echo "myVal = $myVal"
  if [ $myVal -eq $fsId ];then
    errorOut=1
    echo "Found equal: errorOut = $errorOut"
  fi
done
echo "Outside loop: errOut = $errorOut"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to get the value set inside $scope

From Dev

Unable to get the value of variable inside a function

From Dev

How to get a value from inside of an element in HTML and set it as variable in JS

From Dev

Unable to set variable value in callback

From Dev

Unable to set angular variable inside callback

From Dev

Angular JS: Unable to set value to ng-model variable inside ng-repeat

From Dev

Unable to Set a value inside StatusCode Callback

From Dev

How is the default TERM shell variable value set?

From Dev

Set variable value inside switch statement Tcl

From Dev

How to set the value of a liquid variable inside of Javascript

From Dev

Shell variable inside variable

From Dev

Shell variable inside variable

From Dev

Gulp task - unable to set variable value

From Dev

Unable to print value of shell variable stored in another variable

From Dev

Unable to get accurate record count of a csv file

From Dev

Unable to get an accurate threshold of an image with a bright spot

From Dev

How to get all values from a variable made of value separated by a pipe ( | )?

From Dev

Get or Set localStorage Value inside Object

From Dev

Get or Set localStorage Value inside Object

From Dev

get the value of variable exist inside the ajax

From Dev

Get value of object inside a for loop with dynamic variable

From Dev

get the value of variable inside other function javascript

From Dev

Unable to get hidden form value into javascript variable

From Dev

Unable to get DLookup value with variable field

From Dev

Set variable inside keypress() event and get one inside keyup() event

From Dev

How to retain the value of a variable inside for loop in shell script

From Dev

Change Shell script variable value inside AWK conditional block

From Dev

Unable to assign value in a variable after Substring | Unix Shell Scripting

From Dev

How to set Object Value equals Object value inside variable

Related Related

  1. 1

    Unable to get the value set inside $scope

  2. 2

    Unable to get the value of variable inside a function

  3. 3

    How to get a value from inside of an element in HTML and set it as variable in JS

  4. 4

    Unable to set variable value in callback

  5. 5

    Unable to set angular variable inside callback

  6. 6

    Angular JS: Unable to set value to ng-model variable inside ng-repeat

  7. 7

    Unable to Set a value inside StatusCode Callback

  8. 8

    How is the default TERM shell variable value set?

  9. 9

    Set variable value inside switch statement Tcl

  10. 10

    How to set the value of a liquid variable inside of Javascript

  11. 11

    Shell variable inside variable

  12. 12

    Shell variable inside variable

  13. 13

    Gulp task - unable to set variable value

  14. 14

    Unable to print value of shell variable stored in another variable

  15. 15

    Unable to get accurate record count of a csv file

  16. 16

    Unable to get an accurate threshold of an image with a bright spot

  17. 17

    How to get all values from a variable made of value separated by a pipe ( | )?

  18. 18

    Get or Set localStorage Value inside Object

  19. 19

    Get or Set localStorage Value inside Object

  20. 20

    get the value of variable exist inside the ajax

  21. 21

    Get value of object inside a for loop with dynamic variable

  22. 22

    get the value of variable inside other function javascript

  23. 23

    Unable to get hidden form value into javascript variable

  24. 24

    Unable to get DLookup value with variable field

  25. 25

    Set variable inside keypress() event and get one inside keyup() event

  26. 26

    How to retain the value of a variable inside for loop in shell script

  27. 27

    Change Shell script variable value inside AWK conditional block

  28. 28

    Unable to assign value in a variable after Substring | Unix Shell Scripting

  29. 29

    How to set Object Value equals Object value inside variable

HotTag

Archive