首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么是unix-shell条件下的-w运算符?

什么是unix-shell条件下的-w运算符?
EN

Stack Overflow用户
提问于 2014-10-20 03:08:19
回答 3查看 98关注 0票数 0

看起来它就像是一个倒置...

示例:

代码语言:javascript
复制
#!/bin/bash
set -x
#a=1
b=2
 if [ "$a"  -o -w  "$b" ]; then
   echo "ok"
 else 
   echo "fail"
 fi

返回"fail“。

但我不确定,因为

代码语言:javascript
复制
#!/bin/bash
set -x
#a=1
#b=2
 if [ "$a"  -o -w  "$b" ]; then
   echo "ok"
 else 
   echo "fail"
 fi

也会返回"fail“。如果打开replace -w!这将返回"ok“。

请给我看一下这个操作员的文件在哪里。Bash和sh手册只包含-a和-o操作符。

EN

回答 3

Stack Overflow用户

发布于 2014-10-20 03:11:51

这在man bash中有记录,同样的摘录也可以通过help test获得

代码语言:javascript
复制
  -w FILE        True if the file is writable by you.
票数 3
EN

Stack Overflow用户

发布于 2014-10-20 03:11:26

它测试文件是否存在以及是否可写。阅读test命令的手册。

票数 2
EN

Stack Overflow用户

发布于 2014-10-20 19:24:17

只有一些额外的信息:

代码语言:javascript
复制
[ -e file ] : if "file" exists
[ -f file ] : if "file" exists and it is a file
[ -s file ] : if "file" exists and it is not empty
[ -d file ] : to check if "file" exists and it is a directory
[ -r file ] : if "file" exists and readable
[ -w file ] : if "file" exists and writable
[ -x file ] : if "file" exists and it is executable
[ -O file ] : if "file" exists and it is owned by current user
[ -G file ] : if "file" exists and default group same as the current user
[ file_1 -nt file_2 ] : if "file_1" newer than "file_2"
[ file_1 -ot file_2 ] : if "file_1" older than "file_2"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26454260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档