Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to test for file or directory in Fish

📅 2014-Feb-27 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ fish, test ⬩ 📚 Archive

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