0

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
  • Is the name file.sh or file_name.sh? What does ls -l file.sh show?
    – ubfan1
    Jun 25, 2015 at 16:22
  • @newto10 Can you try running it in bash? bash ./file.sh Jun 25, 2015 at 17:10

2 Answers 2

2

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.

0

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

Not the answer you're looking for? Browse other questions tagged .