相关疑难解决方法(0)

Shell Script 中 -n、-z、-x、-L、-d 等的含义是什么?

我经常.sh在条件 sintaxis 中的文件Shell Script 中找到这样的:

if [ -n "condition" ]; then ...
if [ -z "condition "]; then ...
if [ -x "condition" ]; then ...
if [ -L "condition" ]; then ...
if [ -d "condition" ]; then ...
Run Code Online (Sandbox Code Playgroud)

这些 -n, -z, -x, -L, -d是函数或者它是如何命名的,它的目的是什么?

linux bash shell

5
推荐指数
1
解决办法
1831
查看次数

CentOS 和 Ubuntu 上的“常规文件”是什么?

我的环境是:

  • CentOS 6.9
  • Ubuntu 16.04 LTS

GNU coreutils 8.4 有 test 命令来检查文件 using-f选项。

man test 显示

  -f FILE
         FILE exists and is a regular file
Run Code Online (Sandbox Code Playgroud)

“常规文件”的定义对我来说是模棱两可的。

在终端上,我做了

$ touch afile
$ ln -fs afile LN-FILE
Run Code Online (Sandbox Code Playgroud)

然后,我执行了以下脚本(check_file_exist_180320_exec)

#!/usr/bin/env bash
if [ -e LN-file ]
then
    echo "file exists [-e]"
fi

if [ -f LN-file ]
then
    echo "file exists [-f]"
fi
Run Code Online (Sandbox Code Playgroud)

对于 CentOS 和 Ubuntu,对于符号链接文件 (LN-FILE),都显示 -e 和 -f。

但是, ls -l 返回l:symbolik link(不是-:regular file)LN-FILE …

linux file-type

2
推荐指数
1
解决办法
489
查看次数

标签 统计

linux ×2

bash ×1

file-type ×1

shell ×1