LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to add my scripts to the path (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-add-my-scripts-to-the-path-607410/)

hugene 12-17-2007 01:53 PM

how to add my scripts to the path
 
Hello

I don't have root or sudo.

I create a one liner launch script, I want to add it to my path so that I can call it from anywhere.

Here is the script:

#!/bin/sh
vncviewer <...>

its in a file:

~/MyScripts/bin/VNC

I added the directory ~/MyScripts/bin to my PATH variable.

Now, if I type VNC, the script does not get found! Why is that?

Thank you very much

bsdunix 12-17-2007 01:59 PM

Code:

$ echo $PATH
Does the output include /home/<your_username_here>/MyScripts/bin? It is case sentive.

hugene 12-17-2007 02:03 PM

Yes; like I say, the directory it in my PATH. Its actually the first entry

hugene 12-17-2007 02:06 PM

However, my shell doesnt start with $

I have

<computer name>{<my user name>}<command number>:

can it be a shell problem?

jschiwal 12-17-2007 02:21 PM

Most users use ~/bin/ for their scripts. Is the executable bit set on the script?

hugene 12-17-2007 02:43 PM

Ok, I moved the directory to ~/bin and changed my PATH variable

What is the executable bit, and how do I set it?

Thanks

forrestt 12-17-2007 02:58 PM

The executable bit is a part of the filesystem that tells the system that the file can be executed (or run). There are also bits for reading and writing. These bits can be turned for any combination of the owner of the file (u for user), the group that owns the file (g) and others (o).

Code:

chmod u+x ~/bin/scriptname
will turn on the bit for user (or owner). You can also set the bits for all three at once by leaving off the u.

HTH

Forrest

hugene 12-18-2007 10:42 AM

I tried it, and it makes no difference, I still cannot call my script from another location.

There is a star at the end of the file name, I don't know what that means...

rsashok 12-18-2007 12:02 PM

"star" at the end means that you script is executable, e.g. has 'x' in its attribute. Could you post exact output of:
echo $PATH
BTW: your shell prompt configuration doesn't really matter on the output of shell commands.

hugene 12-19-2007 09:15 AM

Here it is (I put some hard returns on purpose, not to make the page too wide):

Quote:

<CPU NAME>{<USER_NAME>}86: echo $PATH
/home/<USER_NAME>/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/var/lib/dosemu:
/usr/games:/opt/bin:/opt/gnome/bin:/opt/kde3/bin:/opt/kde2/bin:/opt/kde/bin:/usr/openwin/bin:
/opt/cross/bin:/usr/bin/X11:/usr/lib/mit/bin:/usr/lib/mit/sbin:/pub/linux/noarch/bin:/pub/linux/i386/nodist/java/bin:/opt/rational/clearcase/bin:/opt/novell/iprint/bin:/usr/lib/qt3/bin
<CPU NAME>{<USER_NAME>}87:

rsashok 12-19-2007 10:36 AM

Path looks good: directory "/home/<USER_NAME>/bin" is there. Make sure that your script is in this directory.
'cd' to any other directory and do "ls /home/<USER_NAME>/bin", and you must see you script in the list. If this
is the case you should be able to execute the script from any location.

forrestt 12-19-2007 10:46 AM

What happens if you cd to the directory the script is in and type "./VNC" (The script is in caps?)

Let us know,

Forrest

hugene 12-19-2007 04:03 PM

I do see the file when I do ll /home/<USER_NAME>/bin.

As for the second question, this is how I have been running the script till now: just cd to that directory and execute ./VNC

It's a total mystery to me....

rsashok 12-19-2007 07:08 PM

That is really strange! For the sake of the experiment, try to move your '/home/USER_NAME/bin' at the end of the path.
You could do it by manipulating PATH variable in your .bashrc and .bash_profile in home directory.

LinuxCrayon 12-20-2007 01:47 AM

You say you always
Code:

cd
to the directory and execute from the directory. Can you execute it while in another directory? That is, can you type
Code:

/home/$username/bin/VNC
?

If you can, and although this is a ridiculous hack, you could try creating an alias...

Again, that's a ridiculous hack to make it work, and you would have to create an alias for every script / program you write...but it should work.

If you can't execute the script by typing
Code:

/home/$username/bin/VNC
, then I'm really stumped...


All times are GMT -5. The time now is 07:32 AM.