I have tried executing this file with every possible alternative but still no luck.chmod +x file.sh
, ./file.sh
and also checked permissions window everything looks fine.
error looks like this --> sh: 0: Can't open ./file_name.sh
2 Answers
When you execute a .sh file using ./, assuming that the permissions allow it, you are saying to the operating system to execute the file with that name in the present working directory.
So to run the file using ./file.sh
make sure you use cd
to get to the directory containing the script file, before attempting to run the script.
If you're not in that directory, you can use the entire file path to run the script. If however the script is in a directory listed in your user's $PATH, then just typing the name of the script file would execute it, just like all the regular commands such as cd
, ls
etc.
If file.sh is a bash script you should set the shebang on the first line of the script. It should look like this: first hash mark then exclamation mark and then path to the interpreter (bash, ksh...) #!/bin/bash
bash ./file.sh