开发者

Environment variables available in startup scripts

When using startup scripts on Linux / Ubuntu, can I access environment variable开发者_运维知识库s such as HOME or are these specific to the user/configuration that is loaded afterwards?


Yes and no. Some variables are specific to your instalation, others to the shell running the init scripts. A simple way to know the minimal set available is with:

/usr/bin/env -i /bin/sh -c set

On my system (fedora 15) this end up running bash and outputing:

BASH=/bin/sh
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_EXECUTION_STRING=set
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="2" [2]="10" [3]="1" [4]="release" [5]="i386-redhat-linux-gnu")
BASH_VERSION='4.2.10(1)-release'
DIRSTACK=()
EUID=xxx
GROUPS=()
HOSTNAME=xxx
HOSTTYPE=i386
IFS=''
MACHTYPE=i386-redhat-linux-gnu
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/local/bin:/bin:/usr/bin
POSIXLY_CORRECT=y
PPID=xxx
PS4='+ '
PWD=/home/xxx
SHELL=/bin/zsh
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=1
TERM=dumb
UID=xxx
_=/bin/sh

In Ubuntu /bin/sh is a symlink to dash, the output will be more like:

IFS=''
LINENO='1'
OPTIND='1'
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
PPID='xxx'
PS1='$ '
PS2='> '
PS4='+ '
PWD='/home/xxx'

As a general rule $HOME is not a good candidate, if you need the home directory of a particular user, use ~username instead like ~www-data, ~ftp, or ~root.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜