Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm quite new to bash scripting and have been going reasonably well but have run into an issue.

I am trying to create a script that uses a forward slash (/), however, I keep getting the error message /: is a directory.

So basically what I need is to pass the command test/(hello) to a program in the terminal. So I have added backslashes to make it work: test\/\(hello\), however, I get this error. What is wrong here?

share|improve this question
where does the script use the forward slash? It sounds like you are successfully passing the argument to the command/script, but that there is an error in the script. Can you give us a more detailed example? Also, doesn't it mention a line number or something? – njsg Dec 12 '12 at 6:53

This should only happen if you are not passing a command before the argument. You need to invoke commands like so:

command [args ...]

If you invoke it like this, it will work.

$ echo test/\(hello\)

For the record, it's generally much easier (and much more readable) to quote arguments instead of escaping all metacharacters. You can do this using " and ' (there's good information about this here).

share|improve this answer
Upvoted. The shell will interpreted text separated only by slashes as directories, not commands/arguments. The forward slash can be used in arguments of, for example, Perl scripts (requires configuring Getopt::Long or rolling your own), but still requires the space between the command and arguments -- again, this is a shell requirement. – laebshade Dec 12 '12 at 14:41

If you need to pass the exact string test/(hello) to a program, put it between single quotes:

someprogram 'test/(hello)'

Every character is interpreted literally between single quotes, except the single quote character itself. If you need a single quote character in the string, pass it as '\'' (end literal string, quote next character, single quote interpreted literally, start literal string).

echo 'Lasciate ogne speranza, voi ch'\''entrate'

This is unrelated to the error message you show here. /: is a directory means that you tried to execute / as a program. There is presumably a place where you tried to write the full path to a program but left an extra space, as in

/ path/to/program

There may be other punctuation characters making this less obvious, or control characters in that message. To facilitate debugging, put set -x on the second line of the script, just after the initial #! line, so that the shell will print a trace of every line it executes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.