Shell Programing - How to get child process variable

Discussion in 'Programming' started by bunbunx2, Jul 11, 2012.

  1. #1
    I have this chunk of code:

    var1=0

    while loop
    do
    var1="1";
    done

    echo "$var1";

    THe result was 0, instead of 1. However, if I echo inside the while loop, it is output as 1. I know .sh can't pass a sub process (child process) to a parent process. How do I alter code to reflect the var1 changes in the loop after the loop ends?

    I saw export as an option but I not sure how to implement it.
     
    bunbunx2, Jul 11, 2012 IP