How to test for file or directory in Fish

In the Fish shell, the test command can be used to test if a file or directory exists. It is useful to use this command in fish configuration files, to check before sourcing a file.

To test if a file exists:

if test -e ~/.foobar
    echo "File exists"
end

To test if a directory exists:

if test -d ~/.hello
    echo "Dir exists"
end

Tried with: Fish 2.1.0 and Ubuntu 12.04 LTS

Advertisements

One thought on “How to test for file or directory in Fish”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s