Friday, May 3, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 106234  / 3 Years ago, sat, october 23, 2021, 7:45:26

I am new to Linux, and I have a shell script (.sh) file I on my Desktop that I want to run.


This is the content of the test.sh file on my Desktop directory:


#!bin/bash
#test.sh
echo "test"

I want to run (execute) test.sh through the terminal. These are the commands that I'm using:


cd Desktop

I give permission to run test.sh with:


chmod +x test.sh

and then try to open the file:


test.sh

But I get this error:


test.sh: command not found

and when I enter test.sh with ./, I again get this error:


bash: ./test.sh: bin/bash: bad interpreter: No such file or directory

What am I doing wrong?


More From » command-line

 Answers
7

bash: ./test.sh: bin/bash: bad interpreter: No such file or directory


Replace:


#!bin/bash

With:


#!/bin/bash

bin/bash is a path relative to the current directory. /bin/bash is an absolute path that works whatever the current directory is.


Also, have a look at your PATH:


echo $PATH

If you place test.sh in any directory listed there and you will will be able to execute it without the ./ or other path specifier. Many people create a $HOME/bin directory, place all their scripts there, and add it to their PATH.


[#22451] Monday, October 25, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
percol

Total Points: 493
Total Questions: 116
Total Answers: 107

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;