how to run sh file in linux command line

4.3k views Asked by At
//init.sh

#!/usr/bin/env bash

export PATH="${HOME}/.pyenv/scripts:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

pyenv shell ammt-crawler

I want to run init.sh file in linux command line
And make sure pyenv shell ammt-crawler line is executed.

but When I just put ./init.sh nothing happend.
is there why to execute the init.sh file in linux?

(ps) if you can please explain to me what export , eval mean inside of this init.sh

2

There are 2 answers

0
Dewald Abrie On

Try to add execute permissions to the script :

chmod +x unit.sh

and try running it again.

0
insert_name_here On

Comments in bash start with #, not //. Also, the shebang (#!/usr/bin/env bash) must be on the first line of the file to have any effect. So the script should be:

#!/usr/bin/env bash

# init.sh

export PATH="${HOME}/.pyenv/scripts:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

pyenv shell ammt-crawler

Also, if you want to be able to execute it with just ./init.sh, it needs to be executable. Run this command to make it executable:

chmod +x init.sh