The variants of ksh

Points

1. If you want to share the variants in a shell to the the children of the current processes. There are 2 ways in ksh,
  1) . setEnv.ksh
  2) eval "setEnv.ksh"

2. You can define a variants in the 3 ways, they are similar
  
  1) OUTPUT="test"
  2) OUTPUT="test"
      export OUTPUT
  3) typeset OUTPUT="test"

   The difference are,

   1) Typeset can set the variant as read-only.

   2) The exported variants can be inherited by child processes.

3. What is diference between $VARIANT_NAME and ${VARIANT_NAME}?
  1) $VARIANT_NAME populates the VARIANT_NAME to characters as many as possible. For example, $Fest equels ${Fest}.
  2) ${VARIANT_NAME} can use REG to populate the expression values. For example, TEST="/opt/sfw/gcc" echo ${TEST%/*}, will print /opt/sfw


4. Today, I made a test for the variants in ksh. I summarize the deals about ksh variants here.

 1). All of the variants defined both in global area and inside function share the same variant area. Please see #2, #3 and #4.
 2). If you define a variant in global area, you can get it inside a function.
 3). If you define a variant inside a function, you can get it in a global area.
 4). If you define a variant inside a function, you can get it in another function.
 5). It is not the same situation with export keywork or not. That is to say, the exported variants can be inherited by child processes. In the same process, with the export or not, it doesn't matter. But if you want child process to share the variant, you must export them. 
 6). In global area, $0, $1... is the process parameters while inside function is function parameters.

Reference

 http://topic.csdn.net/u/20080602/22/cce87943-b9b1-4117-a138-9ac0b102257f.html

Source

 test1() {
   echo "before test()"
  echo "TEST0: ${TEST0}"
  echo "TEST1: ${TEST1}"
  echo "TEST2: ${TEST2}"
  echo "TEST3: ${TEST3}"
  
  TEST0=$1
  TEST1=$2
  TEST2=$3
   TEST3=$4
  
   echo "after assign parameter inside test()"
   echo "TEST0: ${TEST0}"
  echo "TEST1: ${TEST1}"
  echo "TEST2: ${TEST2}"
  echo "TEST3: ${TEST3}"
 
 
  TEST0="bde"
  TEST1="bde"
  TEST2="bde"
   TEST3="bde"
  
   export TEST2
   export TEST3
 
   echo "after test()"
  echo "TEST0: ${TEST0}"
  echo "TEST1: ${TEST1}"
  echo "TEST2: ${TEST2}"
  echo "TEST3: ${TEST3}"
  
  TEST4="hahaha"
  TEST5="hihihi"
  export TEST5
  echo "TEST4: ${TEST4}"
  echo "TEST5: ${TEST5}"
 }
 
 {
  TEST0="abc"
  TEST1="abc"
  TEST2="abc"
   TEST3="abc"
  
   export TEST1
   export TEST3
  
   echo "before call method"
  
   echo "TEST0: ${TEST0}"
  echo "TEST1: ${TEST1}"
  echo "TEST2: ${TEST2}"
  echo "TEST3: ${TEST3}"
 
   test1 $TEST0 $TEST1 $TEST2 $TEST3
 
   echo "after call method"
  echo "TEST0: ${TEST0}"
  echo "TEST1: ${TEST1}"
  echo "TEST2: ${TEST2}"
  echo "TEST3: ${TEST3}"
  
  echo "TEST4: ${TEST4}"
  echo "TEST5: ${TEST5}"
 }
 
 
 before call method
 TEST0: abc
 TEST1: abc
 TEST2: abc
 TEST3: abc
 before test()
 TEST0: abc
 TEST1: abc
 TEST2: abc
 TEST3: abc
 after assign parameter inside test()
 TEST0: abc
 TEST1: abc
 TEST2: abc
 TEST3: abc
 after test()
 TEST0: bde
 TEST1: bde
 TEST2: bde
 TEST3: bde
 TEST4: hahaha
 TEST5: hihihi
 after call method
 TEST0: bde
 TEST1: bde
 TEST2: bde
 TEST3: bde
 TEST4: hahaha
 TEST5: hihihi

你可能感兴趣的:(.net,gcc)