Examine the output of this (from the directory where the abc.sh resides):
$ type ./abc.sh
type command will first verify that your ./abc.sh is found. If it isn't it will exit saying that it can't find the
./abc.sh file. Then we would have to find out what it is about the filename that it can't be found.
Also, what is the name of the editor you are using to create your script file. If you inadvertently used a Windows edit (through wine) this can cause problems with the line terminators in your script.
Try using and edit such as
gedit. You might use one of those recommended editors and create the same example file as,
abc1.sh and ensure that you have the lines exactly as they are in your edited question.
By the way, the only way I can reproduce the error message that you gave in your question is by leaving out the
abc part of the
These commands will produce the error of your message:
$ sudo .sh
Please keep in mind that each error is unique and important in diagnosing the problem. It's important to test and exact script and give the exact error message.
For example a
permission denied error could be caused by trying to execute a file that doesn't have the execution bit set. This can be set by executing the command that you reference in your question:
$ chmod 777 abc.sh
You could also get the
permission denied error by trying to execute a file that that is owned by
root and doesn't have the world or group bit set for reading. This can be a side effect of using
sudo in your personal space when it's not necessary. The
chmod 777 that you mentioned in your question would also resolve that problem by giving reading and execution permission to all users.
If you have created the file in such that it's owned by root you will have to use the elevated command to change the properties. This will give you access to execute the file:
$ sudo chmod 777 abc.sh
If you have a reason to control who can execute or access the script you might take a look at some of the other options of
$ man chmod
As suggested in the comments to your question, you shouldn't use the elevated command
sudo to run scripts that you are testing. If the testing is in your personal space, you can cause areas of your personal space to have become owned by root... losing personal access to those areas. Some ill formed scripts could also cause corruption to other system files of our OS. The mistyping of your attempt to run the
abc.sh script is an example that errors can happen. If you decided to remove your script or script work directory and mistakenly had a space in the wrong place it could cause serious problems where you least expect.