Unix点命令

编程入门 行业动态 更新时间:2024-10-25 16:22:54
本文介绍了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点命令

本文发布于:2023-07-05 14:42:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1038462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   Unix

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!