2

First and foremost the script is a 'hello world' script and it's stored in ~/jared/bin. Here's the script:

#!bin/bash
echo "hello world"

Based on this question here, I tried:

The file is executable? I used:

chmod 755 my_script

I ran the following commands, and here is the output:

which bash

/bin/bash

and finally,

echo $PATH

/home/jared/bin:/home/jared/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

The file endings are UNIX as I wrote the script in VIM. However to be safe, I wrote additional 'hello world' scripts in Sublime and Atom and received the same error when I ran them.

I even tried running dos2unix on the file.

The script will execute when ran directly from the directory and will execute in any directory if I type bash hello_world However it throws the error if I use ./

I don't know if this will help, but it seems relevant: I can use tab autocomplete on the script if I don't preface it with bash or ./

I fear, I'm making a really stupid mistake here, hopefully someone is prepared to make me feel incredibly silly today. Thanks!

Jared T
  • 23
  • 3

2 Answers2

3

The first line of your script should be

#!/bin/bash
  ^

It needs to be #! followed by an absolute path to bash. Note the slash before /bin.

melpomene
  • 84,125
  • 8
  • 85
  • 148
1

first line should look like:

#!/bin/bash

you forgot the '/' after '!' so the system cannot find correct (absolute) path to bash

Kamil Piwowarski
  • 506
  • 5
  • 15