0

I am trying to run program midnight commander by script.sh and I can run it by using sh, but when I try to run it without sh, I get:

script.sh: command not found

This is script.sh:

#!bin/bash
mc

I found some answers regarding this topic("command not found" when running shell script). In this answer they suggested to run command od -c script.sh to reveal invisible characters. This was the result of that command.

0000000 # ! / b i n / b a s h \n m c \n
0000017

I think that this command did not reveal hidden characters.

Can someone tell me what is the problem here?

Jakov
  • 879
  • 2
  • 17
  • 36
  • Please copy&paste the script or commands and output to your question, don't retype. `#!bin/bash` in the script does not match the `od` output `# ! / b i n / b a s h \n`. There is a missing or additional `/`. – Bodo Sep 14 '20 at 13:53

1 Answers1

3

first give execute permission to script.sh

chmod +x script.sh

then ./script.sh

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • This one is working. But can you tell me why is `script.sh` not working(without `./`)? – Jakov Sep 14 '20 at 13:57
  • 2
    Because commands are search in PATH and the directory `script.sh` is in is not in PATH. – KamilCuk Sep 14 '20 at 14:00
  • I've been thru the same issue on an Ubuntu with [oh-my-bash](https://github.com/ohmybash/oh-my-bash) installed. With `.` added to PATH on a terminal session, not `.bashrc` or `.profile`, like said [here](https://stackoverflow.com/a/47255247/5938182), the script runs as expected when called by name, without `./` before. I think there's a configuration for this, but I couldn't figure it out a solution. On another PC with a clean Ubuntu 20.04, it works as expected. Then it would be interesting to know what is causing that issue. – Diego Bandeira Dec 26 '20 at 01:30