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"
echo
and"TTTTTTT"
../turan_first
to run it - or justturan_first
? See Why do I need to type./
before executing a program in the current directory?