通过一个中间文件进行:

 

#!/bin/bash
 
(
 subvar="hello shell"
 echo "$subvar" > temp.txt
)
 
read pvar < temp.txt
 
echo $pvar