2

test.sh:

#!/bin/bash
echo "helloworld"

I set the file mode to 755. when I try to run the script by typing "./test.sh", I get this:

helloworld
./test.sh: line 2: /root: is a directory

what's going on???

4
  • 1
    what happens when you do '/bin/bash -x ./test.sh; echo $?' Commented Apr 24, 2011 at 15:45
  • 1
    Are you redirecting the output? How exactly are you executing this? What user? Commented Apr 24, 2011 at 15:48
  • 1
    Are you sure you are looking at the same test.sh as you are executing? cat ./test.sh;./test.sh would be interesting to see. Commented Apr 24, 2011 at 15:52
  • not redirecting output. I've tried root and a common user also. Commented Apr 24, 2011 at 15:54

4 Answers 4

1

Put an exit and see

#!/bin/bash
echo "helloworld"
exit
Sign up to request clarification or add additional context in comments.

Comments

1

I'd look for funny business in error/signal handlers and or the PROMPT_COMMAND

So,

echo $PS1
echo $PROMPT_COMMAND
trap

would be in order.

Another approach is to make bash run restricted (which disables a whole slew of options)

#!/bin/bash -r

While the latter may resolve the strange behaviour, it wouldn't explain waht happened

Comments

0

I guess edited from Windows/reused a Windows-file with an \r inside, which you moved around with inserting exit?

Comments

0

I got this error when I accidentally put a ~ on the last line of my script while aiming for the escape key in vim. Because vim uses tildes to fill lines outside the file the mistake was nearly invisible. Removing the line containing the tilde got me rid of the

/root: Is a directory

error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.