Server Fault is a question and answer site for system and network administrators. 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

when I tried to run my .sh file in Redhat using ./

I am getting a error like

[test@tester unix_scripts]$ ./
: No such file or directory
[test@tester unix_scripts]$

I have also set the permission of the file with chmod 777

still the same error

Can anybody help me?

share|improve this question

10 Answers 10

Actually the issue was the script that i used was created in dos, so i converted my script to unix by using dos2unix command. Thanks to all for your valuable help.

share|improve this answer
dos2unix only converts DOS line breaks to UNIX style line breaks. It won't bless the script with the magic to make it compatible with the shell. – Dave Cheney May 28 '09 at 14:14
dos2unix fixes that often for me as well. if the Win line break added at the 1st line - unix cannot find the /bin/sh anymore as it is /bin/sh^M now – webwesen May 28 '09 at 20:02
I've had this issue numerous times too. Always fixed with dos2unix – user4767 May 29 '09 at 19:22

You may have forgotten to put at the first line of your script:


for example: #!/bin/bash
echo Hello World

If you try a simple shell script like the hello world example above? does it work or not ?

By the way; are you sure about SELinux context ? what does : getenforce says ? what does : ls -l says ?

My best advice is try with a very simple script first so you can check every environment and context behaviours.

Hope this helps.

share|improve this answer
the header that i have used is #!/bin/sh in this case how can run the script? – Charly May 28 '09 at 13:38

Double check that you are in the right directory (you can view what is in the directory by typing "ls") and the file's name is "". You may also want to try:

[test@tester unix_scripts]$ sh
share|improve this answer

Is in the unix_scripts directory?

Is there a file or directory that is being referenced in that doesn't exist? Because the error could be coming from within the script, not from the execution of the script...

share|improve this answer

Yes, it should be #! (crash bang!) :)

Can you post the results of the following commands, executed in the directory your script is in?

ls -l
share|improve this answer

Are you using sh or bash? (ie. what is the first line of your script?)

If you are using #!/bin/sh, then you need to ensure /bin/sh exists (type which sh)

You may need to try #!/bin/bash or another shell if /bin/sh is not installed.

share|improve this answer

Try getenforce. If is returns enforcing then selinux is on and your script may need to be in a different context to run.

If getenforce does return enforcing then check dmesg, /var/log/message /var/log/audit/audit.log or wherever selinux logs to on your host to find the exact problem.

Or just try chcon'ing the script to the same context as another script that does run.

To see a files context use ls -lZ.

Or try

chcon --reference=/script/that/will/work /script/that/wont/work

Maybe check the chcon man page, I'm not 100% sure on the --reference syntax.

share|improve this answer

Putting a hashbang on your script won't change what it takes to run it. You have to either set it to be executable (chmod +x and then run it (./, or you can call it as an argument of the shell (sh

You can also put the script in any location from your $PATH variable (e.g. ~/bin/, /usr/local/bin/) and, if it's executable, you can run it from anywhere without referencing its location (

If a script is run without being an argument of the shell, it will by default run in whatever shell you're currently using. That is where the hashbang gets important... if you want to make sure it's run as a bash script, even if the user is using tcsh or ksh or something else, you put #!/bin/bash as the first line of the script.

share|improve this answer

step 1 - check for a shebang on first line of file step 2 - does the shebang point to a real binary? (try which [path after shebang]) step 3 - if step 2 checks out, ./ should work, else.. step 4 - try /full/path/to/sh

what you posted, charly, makes no sense whatsoever

share|improve this answer
please see the webwesen comment for my answer.. – Charly May 29 '09 at 9:15

you need to change the permissions:

chmod +x
share|improve this answer
You need to read the other answers before posting a "new" answer. This exact answer was given over seven years ago. If you agree with an answer, up vote the answer - DO NOT just post a duplicate! That aside, the question actually states that the permissions on the file are 777 already. – Colt Jul 2 at 14:16
man, you have a hobby for Saturdays. – MarianP Jul 2 at 16:41

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.