1.02 子shell对父shell影响
#!/bin/bash

FILE=.bashrc

for i in $(awk -F ':' '{print $6}' /etc/passwd)
do
  [ -d "$i" ] || continue #不存在家目录就跳过此次循环
  [ -r "$i" ] || continue #家目录不可读就跳过此次循环
  (cd $i;[ -e "$FILE" ] && more $FILE)
done

exit 0

加入这个脚本在/root下。执行完这个脚本,退出脚本开启的shell后,父shell所在的位置仍然是/root,这说明在子shell中的目录更改不会影响父shell

上一页➡️

下一页➡️

Calendar Jun 8, 2022
Edit Edit this page
本站总访问量:  次 您是本站第  位访问者