0

I'm quiet new to scripting and trying to learn from videos and books. When I write my first script the bash took it as a command not an executable (yes I used 775). Here's an example for script and the bash error:

#!/bin/bash
echo"TTTTTTT"
exit
turan_first: command not found

I'm so new that I even don't know the problem is. Please help.

3

1 Answer 1

2

When you invoke a program or a script, the shell looks for it the directories declared in the PATH variable. Except if you invoke the program file specifying a path -absolute or relative-
Of course the user calling the script or program file must have executable permission right on the file

aprogram          ## Looks for the file in directories declared in PATH
/path/to/aprogram ## Looks for aprogram in /path/to
./aprogram        ## Looks in current directory for aprogram


See echo $PATH

~/turan_first executable file contains

#!/bin/bash
echo "TTTTTTT"
exit
  • A space is required after the command echo, or shell wont recognize it
  • exit is useless while the script ends normally
  • Call the script with ~/turan_first or while prompt is in ~/, call it with ./turan_first


A good practice is to store all your script in a dedicated directory. Say ~/Scripts
In that case, you get the habit to call your scripts with ~/Scripts/turan_first using auto-completion.
A next step could be to add your Scripts directory to the PATH environment variable. So that you could call your scripts without any path specified.
Edit the bashrc file: nano ~/.bashrc and add the line

export PATH="~/Scripts:$PATH"
3
  • Also need chmod a+x ~/turan_first to make script executable. Jul 28, 2019 at 17:14
  • Thanks for all your help. It's more than I expected. I will do the things that you suggest. But something isn't still clear. I watched 2 videos from different tubers and they didn't need to add ./ or ~/ before the command. They just typed and there was the echo. Is it about some adjustments in .bashrc or it's something that I don't understand?
    – TheL
    Jul 28, 2019 at 21:16
  • videos are not reference, you should better read
    – cmak.fr
    Jul 29, 2019 at 3:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .