运行Linux程序的三种方法

来源:互联网 发布:路由器端口转发是什么 编辑:程序博客网 时间:2024/06/13 19:00
[root@test ~]# cat abc.sh #! /bin/shcd /tmpecho "hello world"[root@test ~]# chmod u+x abc.sh [root@test ~]# ls -lrttotal 224940drwxr-xr-x 2 root root      4096 Dec 11  2012 META-INF-rw-r--r-- 1 root root      4292 May 14  2013 install.log.syslog-rw-r--r-- 1 root root     54254 May 14  2013 install.log-rw------- 1 root root      1333 May 14  2013 anaconda-ks.cfg-rw-r--r-- 1 root root 144608374 May 14  2013 agent.jar-rw-r--r-- 1 root root  85388149 May 14  2013 jdk-7u21-linux-x64.rpmdrwxr-xr-x 3 root root      4096 May 14  2013 networkdrwxr-xr-x 3 root root      4096 Aug 28  2013 Desktop-rwxr--r-- 1 root root        38 May 26 04:50 abc.sh[root@test ~]#[root@test ~]# ./abc.sh ---------->>>第一种执行方法,当前目录没变.hello world[root@test ~]# pwd/root[root@test ~]# sh ./abc.sh ---------->>>第二种执行方法,当前目录没变.hello world[root@test ~]# pwd/root[root@test ~]# source ./abc.sh ---------->>>第三种执行方法,当前目录发生改变.hello world[root@test tmp]# pwd/tmp[root@test tmp]# 

前两种方法的执行过程:
新建一个shell进程来执行abc.sh命令.
新的shell进程执行完毕之后,消亡.
父进程醒来继续接受命令.

第三种(source方式)执行Shell脚本时,不会创建子进程,而是父进程中直接执行.