You're going about this all wrong. Instead, take a minute and learn how other programs do it. Learn about the $PATH
environment variable.
All modern OSes (yes, including Windows) have a concept of the PATH
environment variable. This variable contains a list of all directories where executables (both binary and scripts) are installed.
The traditional solution
Traditionally unix systems are shared among many users. You still see this sometimes these days in servers where the sysadmin, db admin and developers all have their own logins (they don't all login as root right? right ??). So usually if you write your own script or program you normally don't have permissions to install your software in the usual places like /bin
or /usr/bin
or /usr/local/bin
.
Fortunately, each user can modify their own PATH
variable so they can add their own bin
folder to the PATH
variable.
Traditionally the solution is to create a bin
folder in your home directory (you can name it anything you like, some people like programs
but traditionally it is bin
because all the standard folders are bin
):
mkdir ~/bin
Then add the folder to the PATH
variable:
export PATH="$PATH:~/bin"
Sometimes the ~
expansion doesn't work so sometimes you may need to use the full path of your home directory:
export PATH="$PATH:/home/ohiohi/bin"
To make the modification to $PATH
permanent add it to .profile
or .bashrc
Now you can copy the program you wrote to ~/bin
to make it available from anywhere:
cp /Desktop/Folder1/program ~/bin
Now you can just type:
program
The advantages of the traditional solution
Traditionally, everything you own should only be saved inside your home directory. This includes personal scripts, executables etc. The advantage of this is that if you upgrade to a new PC or a new unix based OS all you need to do is copy your home directory over and you can continue with what you're used to.
I've personally been evolving this current home directory form my student days way back in 1997. It started on Linux PPC then moved to Red Hat Linux then moved to Cygwin on Windows95, Windows98, Windows2000, WindowsNT then again to Red Hat Linux then Centos, Ubuntu, Linux Mint and it currently resides on a Mac.
Obviously binary executables won't work if you move to incompatible platforms. This explains why a lot of unix users tend to prefer scripting languages. But you can always recompile.