Unix点命令 [英] Unix dot command

查看:74
本文介绍了Unix点命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码段,下面是我的问题。由于我对Unix完全陌生,因此我什至不确定我应该是google搜索什么。



我知道./Path是在当前路径
中运行特定程序,我也知道。 / PATH是在另一个目录中运行程序。



但是。 ./PATH?

 如果[[-f ./dbatools.pro]];然后
。 ./dbatools.pro-> **这是做什么的?我认为这样的命令是不可能的吗?**
else
。 /app/dbatools/profile/dbatools.pro
fi

echo开始于`date`


解决方案

命令为标准POSIX shell (伯恩,科恩,巴什)的表示法是读取命名文件,就像它是当前文件的一部分一样脚本'。最大的优点是该文件可以设置环境变量和定义函数,并且会影响Shell脚本。通常,如果您以常规命令运行脚本(使用 ./ dbatools.pro sh dbatools.pro ) ,那么环境变量只会影响执行脚本的外壳,而不会影响当前的外壳。



该测试将检查是否存在名为 dbatools.pro 在当前目录中(因此 ./ dbatools.pro )。如果存在,它将使用该文件。如果没有,则使用文件 /app/dbatools/profile/dbatools.pro 。如果无法读取点文件,则会生成错误。



使用Bash时,还有一个替代符号 source ./dbatools。 pro ,可以代替。



请注意,(和 source ,Bash 内置)命令将搜索纯文件(。dbatools)。 pro )放在 $ PATH 上的目录中,但是文件不需要是可执行文件,它只需要可读即可。 / p>

I have the following code snippet, with my question below. As i am completely new to unix, i am not even sure what i should be google searching for to begin with.

I know that ./Path is to run a particular program in the current path I know also that . /PATH is to run a program in another directory.

But what about . ./PATH ?

if [[ -f ./dbatools.pro ]]; then
        . ./dbatools.pro  -> **what does this do ? I don’t think such a command is possible ?** 
else
        . /app/dbatools/profile/dbatools.pro
fi

echo "Started at `date`"

解决方案

The dot . command is standard POSIX shell (Bourne, Korn, Bash) notation for 'read the named file as if it was part of the current script'. The big advantage is that the file can set environment variables and define functions and it affects the shell script. Normally, if you run the script as a regular command (using ./dbatools.pro or sh dbatools.pro), then the environment variables affect only the shell that executes the script, not the current shell.

The test looks to see if there is a file called dbatools.pro in the current directory (hence ./dbatools.pro). If there is, it uses that file; if there is not, then it uses the file /app/dbatools/profile/dbatools.pro. It will generate an error if it cannot read the file it 'dots'.

With Bash, there's an alternative notation, source ./dbatools.pro, that can be used instead. It is borrowed from the C shell.

Note that the . (and source, a Bash builtin) commands will search for a plain file (. dbatools.pro, for example) in a directory on $PATH, but the file does not need to be executable — it only needs to be readable.

这篇关于Unix点命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆