How to run a .sh file in Red Hat?
Solution 1
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.
Solution 2
You may have forgotten to put at the first line of your script:
#!/bin/bash
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
say?
What does: ls -l test.sh
say?
My best advice is try with a very simple script first so you can check every environment and context behavior.
Solution 3
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 "test.sh". You may also want to try:
[test@tester unix_scripts]$ sh test.sh
Related videos on Youtube
Charly
Updated on September 17, 2022Comments
-
Charly almost 2 years
When I tried to run my
.sh
file in Redhat using./test.sh
I am getting a error like
[test@tester unix_scripts]$ ./test.sh : No such file or directory [test@tester unix_scripts]$
I have also set the permission of the file with
chmod 777 test.sh
still the same error
Can anybody help me?
-
Charly about 15 yearsthe header that i have used is #!/bin/sh in this case how can run the script?
-
Dave Cheney about 15 yearsdos2unix 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.
-
webwesen about 15 yearsdos2unix 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
-
Charly about 15 yearsplease see the webwesen comment for my answer..
-
Pilgerstorfer Franz about 15 yearsI've had this issue numerous times too. Always fixed with dos2unix
-
Colt almost 8 yearsYou 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.
-
MarianP almost 8 yearsman, you have a hobby for Saturdays.