Skip to content

Instantly share code, notes, and snippets.

@jpzhu
Created June 22, 2014 12:35
Show Gist options
  • Save jpzhu/7c3e57c0d10bb7457603 to your computer and use it in GitHub Desktop.
Save jpzhu/7c3e57c0d10bb7457603 to your computer and use it in GitHub Desktop.
script running

如何判断脚本是以独立进程运行的,还是被source命令调用的?
方法1: 可以查看$0变量的值,如果是以source运行,$0应该为bash或sh.
方法2: 可以查看ps -o comm= -p $$的输出,也就是打印当前进程的命令,输出洁果和方法1是一样的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment