-2

My script is supposed to: recursively look for files and directories whose names contain given strings, using find, starting in the current directory. If no arguments are given the message Missing argument(s) shall be printed before returning the error code 1 to the shell.

This is the script:

#!/bin/bash/
if ["${#}" -eq 0]
  then
     echo "Missing argument(s)"
     exit 1
else
  find .  -name "*$@*"
fi

I tried to use this in the terminal, but I got this error: bash: ./myfind: /bin/bash/: bad interpreter : Not a directory

Why? Is my code correct?

  • 1
    -1 This question does not show any research effort. – Daniel Beck Jan 17 '12 at 10:40
6

You need to delete the slash at the end of the first line. /bin/bash is the interpreter.

| improve this answer | |
2

You also need a space between [ and ", and between 0 and ].

Bonus: You can simplify "${#}" to just $# - There's no need to quote a variable which is always going to be a number, and there's no need to use braces unless you've got more than just a single variable within the string.

| improve this answer | |
  • Great! thanks!Both these suggestions are valuable! – Anson Jan 18 '12 at 4:44

Your Answer

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

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