Last active
          August 29, 2015 14:24 
        
      - 
      
 - 
        
Save mattintosh4/17c74a4d9e425eeb89e1 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # 変数 VAR1 を定義 | |
| VAR1=1 | |
| # 変数 VAR2 を定義 | |
| VAR2=2 | |
| # 変数 VAR2 をエクスポート | |
| export VAR2 | |
| # カレントシェルで VAR1 と VAR2 を表示 | |
| declare -p VAR1 VAR2 | |
| # 子プロセスで VAR1 と VAR2 を表示 | |
| bash -c 'declare -p VAR1 VAR2' | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | declare -- VAR1="1" | |
| declare -x VAR2="2" | |
| bash: line 0: declare: VAR1: not found | |
| declare -x VAR2="2" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # 子プロセスで VAR1 と VAR2 を定義、VAR2 をエクスポートして表示 | |
| bash -c ' | |
| VAR1=1 | |
| VAR2=2 | |
| export VAR2 | |
| declare -p VAR1 VAR2 | |
| ' | |
| # カレントシェルで VAR1 と VAR2 を表示 | |
| declare -p VAR1 VAR2 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | declare -- VAR1="1" | |
| declare -x VAR2="2" | |
| ./gistfile3.sh: line 11: declare: VAR1: not found | |
| ./gistfile3.sh: line 11: declare: VAR2: not found | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # 子プロセスで VAR1 と VAR2 を定義、VAR2 をエクスポートして表示 | |
| # 孫プロセスで VAR1 と VAR2 を表示 | |
| bash -c ' | |
| VAR1=1 | |
| VAR2=2 | |
| export VAR2 | |
| declare -p VAR1 VAR2 | |
| bash -c '\''declare -p VAR1 VAR2'\'' | |
| ' | |
| # カレントシェルで VAR1 と VAR2 を表示 | |
| declare -p VAR1 VAR2 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | declare -- VAR1="1" | |
| declare -x VAR2="2" | |
| bash: line 0: declare: VAR1: not found | |
| declare -x VAR2="2" | |
| ./gistfile5.sh: line 13: declare: VAR1: not found | |
| ./gistfile5.sh: line 13: declare: VAR2: not found | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # 一時ファイル tempfile を作成 | |
| tempfile=`mktemp` | |
| # tempfile を終了時に削除 | |
| trap "rm ${tempfile}" EXIT | |
| # 子プロセスで変数を定義、tempfile へ出力 | |
| bash -c ' | |
| VAR1=1 | |
| export VAR1 | |
| echo ${VAR1} | |
| ' >${tempfile} | |
| # カレントシェルで VAR1 を表示 | |
| declare -p VAR1 | |
| # tempfile から VAR1 の値を取得 | |
| VAR1=`cat ${tempfile}` | |
| # VAR1 をエクスポート | |
| export VAR1 | |
| # カレントシェルで VAR1 を表示 | |
| declare -p VAR1 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # 一時ファイル tempfile を作成 | |
| tempfile=`mktemp` | |
| # tempfile を終了時に削除 | |
| trap "rm ${tempfile}" EXIT | |
| # 子プロセスで変数を定義 | |
| # 定義式 ``declare -x VAR1="1"'' を tempfile へ出力 | |
| bash -c ' | |
| VAR1=1 | |
| export VAR1 | |
| declare -p VAR1 | |
| ' >${tempfile} | |
| # カレントシェルで VAR1 を表示 | |
| declare -p VAR1 | |
| # tempfile を読み込み ``declare -x VAR1="1"'' を実行 | |
| . ${tempfile} | |
| # カレントシェルで VAR1 を表示 | |
| declare -p VAR1 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | bash: line 15: declare: VAR1: not found | |
| declare -x VAR1="1" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment