Discussion Locked

Starting script problem

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

When I make a script and make it executable it starts if I type like this: ./myscript. The question is why I must type ./ infront of scripts name.
10x.

9 replies

by insatiable

Hi!
When you're executing a script in the Unix environment, the ./ tells the computer that you want to work with the file in the current directory, rather than search through your PATH setting.
I hope that helps.
Good luck!!
Melissa

by peterdoh

When you login to shell you could set current directory in PATH with a (.) and you would not need to type ./ because current directory would be in PATH.

PATH=/usr/bin:/usr/sbin:.
export PATH

by cavedweller

There is a security risk in placing "." in your path, especially if you are a priviliged user or administrator. Adding "." allows someone to write a program with the same name as a trusted program, place it in an unprotected directory and have you run it for them when you think you're running the real one. If you feel you must place "." in your path be sure to put it at the end. Imagine your embarrasment if you ran something called "ls" that actually did "cd /; rm -rf *"

by cpfeiffe

Add the exact location of the script to your path (not using .). If the script is /admin/scripts/myscript, just add /admin/scripts to your path variable in either your .profile or .cshrc (depending on what shell you use.

This discussion is closed to new replies.