What does -f mean in bash

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 $PID does in

#!/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

8

5 Answers

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

Fortunately, the Bash Reference Manual is available online, at . It's the first hit when you Google for "Bash manual". §6.4 "Bash Conditional Expressions" says:

-f file

True if file exists and is a regular file.

0

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

Check this out for all file test operators:

1

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

1

-f checks if the file exists and is a regular file.

[ -f "$var" ] 

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like