Naming Your Script Test

Problem

You typed up a bash script to test out some of this interesting material that you’ve been reading about. You typed it exactly right, you even remembered to set the execute permissions on the file and put the file in one of the directories in $PATH, but when you try to run it, nothing happens.

Solution

Name it something other than test. That name is a shell built-in command.

Discussion

It is natural enough to want to name a file test when you just want a quick scratch file for trying out some small bit of code. The problem is that test is a shell built-in command, making it a kind of shell reserved word. You can see this with the type command:

$ type test
test is a shell builtin
$

Since it is a built-in, no adjusting of the path will override this. You would have to create an alias, but we strongly advise against it in this case. Just name your script something else, or invoke it with a pathname, as in: ./test or /home/path/test.

See Also

  • “Built-in Commands and Reserved Words” in Appendix A

Get bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.