-f 在 bash 中是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30825762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:00:02  来源:igfitidea点击:

What does -f mean in bash

bashoperators

提问by Atrotors

I was looking at how to use runit to run gunicorn. I was looking at the bash file and I don't know what -f $PIDdoes in

我正在研究如何使用runit 来运行 gunicorn。我一直在寻找的是bash文件,我不知道是什么-f $PID的呢

#!/bin/sh

GUNICORN=/usr/local/bin/gunicorn
ROOT=/path/to/project
PID=/var/run/gunicorn.pid

APP=main:application

if [ -f $PID ]; then rm $PID; fi

cd $ROOT
exec $GUNICORN -c $ROOT/gunicorn.conf.py --pid=$PID $APP

Google is useless in this case because searching for flags is useless

在这种情况下,谷歌是无用的,因为搜索标志是无用的

回答by ruakh

Google is useless in this case because searching for flags is useless

在这种情况下,谷歌是无用的,因为搜索标志是无用的

Fortunately, the Bash Reference Manualis available online, at http://www.gnu.org/software/bash/manual/bashref.html. It's the first hit when you Google for "Bash manual". §6.4 "Bash Conditional Expressions"says:

幸运的是,Bash 参考手册可在线获取,网址http://www.gnu.org/software/bash/manual/bashref.html。当您在 Google 上搜索“Bash 手册”时,这是第一次命中。第 6.4 节“Bash 条件表达式”说:

-f file

True if fileexists and is a regular file.

-f file

如果文件存在并且是常规文件,则为真。

回答by Andrzej Pronobis

-f - file is a regular file (not a directory or device file)

-f - 文件是一个普通文件(不是目录或设备文件)

Check this out for all file test operators: http://tldp.org/LDP/abs/html/fto.html

检查所有文件测试操作员:http: //tldp.org/LDP/abs/html/fto.html

回答by askvictor

The [is the same as the command testwhich allows you to test certain things. Try help testto find out what the flags are. Things to be careful with are spaces - the [needs a space after it.

[test允许您测试某些内容的命令相同。尝试help test找出标志是什么。需要注意的是空格 -[在它之后需要一个空格。

回答by whrobbins

-fchecks if the file exists and is a regular file.

-f检查文件是否存在并且是一个普通文件。

回答by Jahid

[ -f "$var" ] 

Checks if $varis an existing file (regular file). Symbolic link passes this test too.

检查是否$var是现有文件(常规文件)。符号链接也通过了这个测试。