shell 脚本中方括号的用途 [英] Purpose of square brackets in shell scripts

查看:33
本文介绍了shell 脚本中方括号的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中一个 shell 脚本中遇到了这一行:

I came across this line in one of the shell scripts:

[-f $host_something ] && .$host_something

带 -f 开关的方括号应该做什么,以及将它与相同的环境变量与"有什么意义

What is the square brackets with the -f switch suppose to do and what is the point of 'ANDING' it with the same environment variable

这可能是一个非常基本的 shell 脚本功能..但是尝试在 google 中查找答案很困难,因为我无法向搜索引擎充分解释我想要什么.

This might be a very basic shell scripting feature.. but trying to lookup the answer in google was tough as I could not sufficiently explain to the search engine what I wanted.

推荐答案

[ 实际上是一个实际的二进制文件.它是 test(1) 命令的别名.它将忽略它应该是 ] 的最后一个参数.运行 man test 以获取更多信息.这不是真正的 shell 语法.

The [ is actually an actual binary. It's an alias for the test(1) command. It will ignore it's last argument which should be ]. Run man test for further information. It's not really shell syntax.

这篇关于shell 脚本中方括号的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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