这个小数点有什么用处

sh/bash/dash/ksh/zsh等Shell脚本
回复
anth
帖子: 174
注册时间: 2010-11-09 3:06

这个小数点有什么用处

#1

帖子 anth » 2011-07-24 10:53

# part of the file ~/.bashrc

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

其中. ~/.bash_aliases的第1个小数点是什么意思
头像
dreamcast_sh
帖子: 480
注册时间: 2009-06-14 22:16

Re: 这个小数点有什么用处

#2

帖子 dreamcast_sh » 2011-07-24 11:44

执行脚本的一种方法
想玩生化了。。。
levee
帖子: 3030
注册时间: 2009-10-03 23:31

Re: 这个小数点有什么用处

#3

帖子 levee » 2011-07-24 11:49

. ~/.bash_aliases
这一句,如果不加.将启动一个子shell解释并执行.bash_aliases文件,加了.就在当前shell解释并执行.bash_aliases(准确地说,是在当前shell进程中从文件读取并执行其中的命令并获取返回值)。
上次由 levee 在 2011-07-24 12:31,总共编辑 1 次。
anth
帖子: 174
注册时间: 2010-11-09 3:06

Re: 这个小数点有什么用处

#4

帖子 anth » 2011-07-24 12:19

levee 写了:
. ~/.bash_aliases
这一句,如果不加.将启动一个子shell解释并执行.bash_aliases文件,加了.就在当前shell解释并执行.bash_aliases。
谢谢
头像
ChenFengyuan
帖子: 770
注册时间: 2008-03-23 0:39

Re: 这个小数点有什么用处

#5

帖子 ChenFengyuan » 2011-07-24 12:21

man dash
. file
The commands in the specified file are read and executed by the shell.
man bash
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell environ‐
ment and return the exit status of the last command executed from
filename. If filename does not contain a slash, file names in PATH
are used to find the directory containing filename. The file
searched for in PATH need not be executable. When bash is not in
posix mode, the current directory is searched if no file is found in
PATH. If the sourcepath option to the shopt builtin command is
turned off, the PATH is not searched. If any arguments are supplied,
they become the positional parameters when filename is executed.
Otherwise the positional parameters are unchanged. The return status
is the status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or cannot
be read.
man zshbuiltins
. file [ arg ... ]
Read commands from file and execute them in the current shell envi‐
ronment.

If file does not contain a slash, or if PATH_DIRS is set, the shell
looks in the components of $path to find the directory containing
file. Files in the current directory are not read unless `.' appears
somewhere in $path. If a file named `file.zwc' is found, is newer
than file, and is the compiled form (created with the zcompile
builtin) of file, then commands are read from that file instead of
file.

If any arguments arg are given, they become the positional parame‐
ters; the old positional parameters are restored when the file is
done executing. The exit status is the exit status of the last com‐
mand executed.
头像
jarlyyn
帖子: 4671
注册时间: 2006-04-12 18:54
联系:

Re: 这个小数点有什么用处

#6

帖子 jarlyyn » 2011-07-24 12:28

具体用途是不加点的话,子进程对变量的所有变动在父进程中不起效。

所以一般牵扯到变量共享的

贴别是调用设置变量参数的自脚本

必须前头带点
taiandotzhang
帖子: 6
注册时间: 2011-06-23 20:51

Re: 这个小数点有什么用处

#7

帖子 taiandotzhang » 2011-07-24 13:01

当我们编辑完一个脚本文件后希望其立即生效。
方法一: 重启shell
方法二: 重启系统
方法三: $ . ./xxx.sh 或者 $ source ./xxx.sh

. 与 source 等价.

:em11
回复