Set PATH using a script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Set PATH using a script
# 1  
Old 02-27-2003
Set PATH using a script

I am a corporate user of Solaris ?? I have to write a lot of scripts to do little repetitive actions. To make this easier I would like to set the PATH so that I do not have to type ./ first before the script name.

Is there an easy script that will allow me to set this path when I log in???

My current path is;
$echo $PATH
/opt/jre1.2.2_05a/bin:/usr/dt/bin:/usr/openwin/bin:/bin:/usr/bin:/usr/ucb:/usr/openwin/bin:/opt/oracle/7.3.4/bin:/app/icop/aircrews/CIP/bin:/app/icop/aircrews/COP/bin:/usr/local/bin

I approached our sys admin people and they advised that this was set up to stop people writing scripts with the same name as existing scripts, lame yeah.
I would ideally like to edit the .bash_profile with ./~ but they will not allow that either.

HELP Please!!!

Smilie
# 2  
Old 02-27-2003
Quote:
From www.math.psu.edu:
When you type a command to be executed, Unix looks in a predefined list of directories to find an executable file of the same name as the command and executes it. This predefined list is called your path. An all-too-common practice by many Unix users is to put the working directory ``.'' in their path so they can execute any executable file in their working directory, wherever they happen to be in the system, just by typing its name.

This is not a big savings: if ``.'' is not in your path you merely have to type ./mycommand instead of mycommand. Moreover, having ``.'' in your path, especially near the beginning of it, puts you at risk. A vandal might create an executable file called ls in some directory. If you are in that directory and type ls, thinking it will list the directory, you will execute the cracker's command; if he were nasty enough, the command could destroy your files or create security holes that the person can later exploit.
If you REALLY need it, create a script that changes your PATH to include your complete home path (ie. /home/username/bin) instead of . - this will at the least keep you from running the wrong scripts. You would then have to run . /home/username/myscript4path to source it to your process.

#!/bin/ksh
export PATH=$PATH:/home/username/bin
exit

(Sorry, haven't messed with bash - should be close though)
# 3  
Old 02-27-2003
Well, if you've been told not to change your PATH, then you perhaps should not do that. If I have a script in my home directory, I use ./script too. But I do it for security. And I have to say that typing ./ does not bother me. But you can avoid that without changing your PATH.

If you use the command:
alias script=/full/path/to/script
then from now on, you can just use "script" to run the command.

alias commands can be put in your .bash_profile file. I wasn't clear if you are allowed to edit that file at all. You could just put your alias commands in a file called "setup" or something. And then use this command:
. ./setup
to cause your shell to process that file. Note that leading dot. This is a little different than running a script. A dot command causes the current shell to read commands from the named file.

So give aliases a try. You get the result you wanted: no leading ./ required. And the sysadmins are happy since you are using the prescribed PATH.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Path set

Something changed on my unix box. Now when I log in it is showing entire path. It used to show only $ prompt before. I know I need to do something in .profile to show only $ prompt Could you please tell me what I should do, to show only $ prompt. (4 Replies)
Discussion started by: raopatwari
4 Replies

2. UNIX for Dummies Questions & Answers

How do I set the path

Very new to this type of thing so go easy on me....... I have downloaded a command language for data display. It came as ncl_ncarg-5.2.1.MacOS_10.6_i386_64bit_gcc421.tar.gz and I unzipped/tarred it into my local directory. The new directory, ncl_ncarg-5.2.1.MacOS_10.6_i386_64bit_gcc421,... (7 Replies)
Discussion started by: davcra
7 Replies

3. Shell Programming and Scripting

How to set PATH using shell script [resolved]

Hi, Can anyone help me on how to set PATH using shell scripting.. Please find the shell script code here.... #!/bin/bash PATH = $PATH:/opt/app/oracle/product/10.2.0/bin export PATH echo $PATH exit When i execute this script i get the following error ./backup.sh: line 2: PATH:... (0 Replies)
Discussion started by: srinivasj
0 Replies

4. UNIX for Dummies Questions & Answers

PATH set but I can't find where!!!!

Hi, Can anybody help with this? When I log into my user account on my box via ssh and then instantly perform an env command I see that my path has been set as follows: PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin My user account uses the ksh shell. In my home directory there is no... (7 Replies)
Discussion started by: Donkey25
7 Replies

5. Solaris

Not Able to Set the path

Hi, I want to set the path for my application so I am setting the path as below -- PATH=${PATH}:.:/envs/mldev/tools:/envs/mldev/common/tools:${HOME}:/bin/p4v:/usr/j2se:/usr/j2se/bin:/usr/j2se/lib or PATH="\ /usr/bin:\ /usr/sbin:\ /usr/dt/bin:\ ... (7 Replies)
Discussion started by: smartgupta
7 Replies

6. UNIX for Dummies Questions & Answers

Set java Path

Hey eveyone, I am new to unix, and I just installed java 6, however it doesn't recognize javac command I tried to set the path such as: set path="/usr/java/jdk1.6.0_06/bin/ but i still got the same error message. any ideas? -andi (1 Reply)
Discussion started by: adtd8
1 Replies

7. UNIX for Dummies Questions & Answers

How to set a path for a command?

Hi, I install java at Fedora Core. So to run any java applications i have to write the complety path. For example, /usr/java/jre1.5.0_11/bin/java "javafile" I want to write only "java" but it said "command not found". How i fix this? Thank you very much Lakis (4 Replies)
Discussion started by: Lakis
4 Replies

8. Shell Programming and Scripting

problem in getting the path of environment variable set in bashrc in my shell script

hi all i have joined new to the group. i have set an variable in my bashrc file. .bashrc PROGHOME=/home/braf/braf/prog export PROGHOME but while using it in my shell script its path is not taken and i had to explicitly give the export command to set the path. in my script... (8 Replies)
Discussion started by: krithika
8 Replies

9. Solaris

set path

hi how do i change the default PATH in my system. i log in as root, and i have .profile file in my / directory. ive put the PATH=.:/usr.......... statement, but that doesnt seem to be working i also wanted to know why exactly we need the profile file in etc? (6 Replies)
Discussion started by: strider
6 Replies

10. UNIX for Dummies Questions & Answers

why the PATH can not be set correctly?

I'm using Linux-Mandrake 8.0 in my laptop. After I logged in as a "root", I added a new path in my .bashrc file (I use bash shell). Then I can observe it has been set correctly by typing echo $PATH. But, when I log in again as a personal account, not "root", then I open my bash shell, and type... (5 Replies)
Discussion started by: yishen
5 Replies
Login or Register to Ask a Question