
| - | subshell | childprocess | 비고 |
|---|---|---|---|
| 자동 inherit | O | X (부모가 export 해줘야함) | |
| 부모에게 영향 | X | X | 부모에게 영향을 끼칠 수 있는 유일한 명령은 현재 쉘에서 source 'file' 뿐임 |
| 실행 명령 | bash -c "cmd" | ./ 'file' bash 'file' | |
| 부모가 bg실행 시킨걸 wait로 기다릴 수 있는가? | X | O |
( )를 사용한 서브 쉘은 외부에 영향 X, exit는 서브쉘만 종료{ }를 사용한 인라인 그룹은 외부에 영향 줌, exit를 쓰면 현재 쉘 종료됨

bash -c "cmd" : auto inherit/bin/bash의 실행 및 옵션/bin/bash [option] command
e.g.,
/bin/bash -c "source oe-init-build-env"
| option | 예제 |
|---|---|
| -c "CMD" | ![]() |
$ ( source "스크립트" ) 와 같음

cat file.txt | while read line; do # <--- | pipe로 실행하는 것은 하나의 서브쉘로 실행됨
eval "$line" & <-- bg
done # <---- 여기 까지
wait <-- 서브쉘의 bg 는 wait로 기다리지 못함
sourcesource filename [args]source filename [args]
filename을 실행 후 적용됨file: bash# ======== temp.sh ============= #
#!/bin/bash
declare -a arr
arr+=(0)
arr+=(1)
arr+=(2)
echo ${arr[1]}
# ============================== #
$ ./temp.sh
1
$ source temp.sh # zsh의 builtin command 'source'가 적용됨,
$ echo ${arr[1]}
0
bash 파일에서 source 사용bash built-in command)
source 사용

./, bash : auto inherit (X)


FILE_LEN=$(cat file.txt | wc -l)
for ((i=1; i<=$FILE_LEN; i++)); do
line=$(awk "NR==$i" file.txt)
eval "$line" & <-- childprocess bg 실행
done
wait <- 기다림
$ pstree -ps PID: PID 기준으로 tree + pid + parentpstree 실행
subprocess.Popen("pstree -ps $$",shell=True,executable="bin/bash")으로 pstree실행

좋은 글 잘 봤습니다, 감사합니다 :)