linux - 如果文件在 linux bash 中为空,我如何获得回显输出?

标签 linux bash

<分区>

我有一个简单的命令来识别文件何时为空但不起作用

 MN=$(echo "$(cat   empty)") ;

if [ MN == "" ]; then echo "This file is empty"; else echo "This file has been edited. You'll need to do it manually."; fi

我做错了什么

请帮帮我

最佳答案

test -s 测试文件是否存在且非空。

if test -e empty && ! test -s empty; then
  echo "This file exists but is empty"
fi

关于linux - 如果文件在 linux bash 中为空,我如何获得回显输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44057500/

相关文章:

ruby-on-rails - 尝试在 ubuntu 16.04 上安装 ruby​​ gems 时权限被拒绝

c++ - Bash 可以从 C++ 程序接收参数或返回值吗?

macos - Mac 上的默认终端 $PATH 位于何处?

linux - Rsyslog 错误消息 RHEL 7

bash - 检查stderr是否是bash中的管道

c - 在 Linux 上显示视频

linux - 使用hadoop2(YARN)时出现连接异常

node.js - 如何在 Node 中的 child.process.exec 中使用的命令中转义 URL 中的字符

Linux:用于非常规文件的 mmap()

linux - 为什么 Linux diff 实用程序在内容相同时产生输出?