Any bash script always gives a command not found

So, I tried to run some simple scripts to manage files in OSX 10.9.5, but every time I try to run a script, it first says that I do not have permission, so I sudo the command, but then throws the command did not find an error .

eg,

sudo ./hello.sh

after entering my password will result in

sudo: ./hello.sh: command not found

hello.sh script consists of this.

#!/bin/bash 
echo 'hello world'

However, if I just run the command echo 'hello world'from the final line, it prints it just fine. I checked the wrong line endings, but they \ n

still new to terminal / command line, so the explanations will be awesome.

+4
source share
2 answers

, , . , , , , .

chmod +x hello.sh 

do

sh hello.sh

.

+4

,

$ chmod +x hello.sh

bash /bin

, bash

$ type -path bash

env

env script

#!/usr/bin/env bash
0

Source: https://habr.com/ru/post/1606333/


All Articles