I try to run a shell script file but failed so far on Ubuntu.

In my terminal:

~/Desktop/FTL/data$ ls
amd64  exe_icon.bmp  FTL  licenses  resources  x86
~/Desktop/FTL/data$ sudo bash ./FTL.sh
[sudo] password for anon: 
bash: ./FTL.sh: No such file or directory
~/Desktop/FTL/data$ sh FTL.sh
sh: 0: Can't open FTL.sh
  • 1
    You can use file FTL and the system will do its best to work out what it is and tell you. – squareborg Sep 20 '13 at 9:27

Well, as can be deduced from the output of ls command, the name of the file is FTL, not FTL.sh. So you should use:

sudo bash ./FTL


 sh ./FTL

or maybe only:


Also be sure that the file is executable, by running:

chmod +x FTL
| improve this answer | |

First thought is change the extension to .sh. Should be able to run as ./FTL.sh. Second, if it's missing the #!/bin/sh at the top of the file, it won't work then either.

Third, if you wind up having sudo commands intermixed with commands that don't require sudo, you can echo <sudo_password> | command.

In this case, best practice (from an automation/QA perspective) is to run your command as ./FTL.sh <sudo_password> and capture the password to use later in the script for each command that will prompt for sudo password.


PW=$1 #sets first parameter
# non-sudo commands
echo $PW | command`

It's also not a bad idea to throw in a yes | when your command asks if you want to continue for any reason. Then you can modify the above to echo $PW | yes | command

I also typically capture all output during testing, which can be accomplished by appending |& tee path/to/logfile.log to the end of any command, if you want to watch it progress in the console, or switch the |& tee to &> if it has a long run time or otherwise don't want to monitor progress.


if echo $PW | yes | command |& tee path/to/logfile.log; then 
  if sed -Fq "Validation Passed" path/to/logfile.log; then
    echo "PASS: returned 'Validation Pass'"
    else echo "FAIL: test did not return 'Validation Pass'"
  else echo "Test Failed"

Just a quickie on the sed command, -F allows you to specify the file name (instead of searching a process output) and -q runs sed quietly and exits after it finishes searching the file/process. See sed documentation for more info.

| improve this answer | |

Always use this command for every script to be executed by server.

chmod +x filename.ext
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.