Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 10891  / 3 Years ago, fri, august 6, 2021, 7:27:44

I am under the impression that if I include the line



#!/bin/bash


at the start of my file, it will be recognized as a bash script that I can run just by



file.sh


instead of



sh file.sh


But in my case, file.sh gives something like test.sh gives test.sh: command not found. Why is that?



UPDATE



I notice I need to use ./. But I thought it will look in the current directory anyway?



./test.sh

More From » bash

 Answers
3

First you need to make sure the file is executable:



chmod +x file.sh



And then to run it, you either need to put it in your PATH, i.e., one of the directories of files the OS searches when looking for files to run, which you can find with echo $PATH, or else you need to type in:



./file.sh



Rather than just type file.sh.



You can just type file.sh, if it's in your PATH, which I recommend. A good place is in ~/bin. Create that folder if it's not there, and under Ubuntu, it'll get added to your path when you log in.


[#43879] Saturday, August 7, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
issfullus

Total Points: 264
Total Questions: 126
Total Answers: 107

Location: Comoros
Member since Mon, Dec 19, 2022
1 Year ago
;