Alias for programs

Hello,

I was wondering if someone could tell me how to set up an alias for a data analysis tool.

With Python,
typing python from terminal gives me python 2.7*
typing python3 from terminal gives me python 3.*

I have a data analysis tool that I learned to compile from the source, by editing my .bashrc

typing root form terminal gives me root-5.35-*
now they came up with a new version ROOT 6.02*,

ROOT 6.02 does not sit well with my older codes because of the differences in declaration of pointers.
a.that() needs to be all swapped to
a->that(), and I’m sure that there are some other things that I am yet to notice. In short scripts that I’ve already written which plays nice with ROOT 5.34 does NOT play nice with ROOT 6.02

I wish to set things up such that
if I type
root, it brings up ROOT 5.*
and root6 giving me ROOT6.*

any idea/suggestions?

Thank you for your time
-SJL

You can put alias statements in the file .alias in your home directory (~/.alias). Because

henk@boven:~> grep alias .bashrc
test -s ~/.alias && . ~/.alias || true
henk@boven:~>

the aliases will be available in all bash sessions you start after doing his.

Hi,

as Henk pointed out you can put your alias in ~/.alias but it can be in ~/.bashrc as well since ~/.alias is just being sourced by ~/.bashrc

Another option is to put that compiled? binary/executable in

~/bin

for single user setup

for system wide setup you can put it in

/usr/local/bin

You can checkout that PATH by

echo "$PATH"

And the output is like this on my side.

/home/jetchisel/bin /usr/local/bin /usr/bin /bin /usr/bin/X11 /opt/kde3/bin

The order is important because the binary/executable is being search in your path from left to right so if when you type your program and the system finds it in ~/bin then that is used if not then the search continues.

The caveat of using ~/.bashrc for your aliases is it assumes you are using bash as your log-in shell.
For system wide aliases you can put it in (non-existent)

/etc/bash.bahsrc.local

Again it assumes bash as the log in shell for all users.

Thank you for the replies,
so I currently have my ROOT 5.34 compiled in
~/ROOT
and ROOT 6.02 compiled in
~/ROOT6,

what could I write in .alias or .bashrc
to make “root” to refer to ROOT5.34 and “root6” to refer to ROOT6.02?

  1. Please do show us things. E.g. do not tell a story about ROOT being in ~/ROOT, but post what happens when you do
ls -l ~/ROOT

Copy/paste computer text complete (that is prompt, command, output and next prompt) in one sweep between CODE tags in your post. You get the CODE tags by clicking on the # button in the tool bar of the post editor.

  1. I never would put such programs dircetly in my home directory. You better organise things in using separte directories for separate things. In this case there is already a directory bin in your home directory. So better move ROOT and ROOT6 there: ~/bin/ROOT and ~/bin/ROOT6. This has the advantage that ~/bin is in your PATH environment variable and will thus be found if you simply call it as
ROOT

from whichever working directory you happen to be.

  1. Check if you, the owner, can excute it. In other words the x-bit for owner must be set. When not do
cd ~/bin
chmod u+x ROOT ROOT6
  1. Now it eems that you do not want to call it as
ROOT
ROOT6

but as

root
root6

There are three (3) solutions here:

a) change the name of the files:

cd ~/bin
mv ROOT root
mv ROOT6 root6

b) when you do not like that, make hard links:

cd ~/bin
ln ROOT root
ln ROOT6 root6
  1. or create aliases in ~…/alias by using the editor you love to create (or edit when it is already there) ~/.alias and ad the lines:
alias root='ROOT'
alias root6='ROOT6'

~> ls -l ~/ROOTtotal 904
drwxr-xr-x  2 sjl users   4096 Dec 21 19:38 bin
drwxr-xr-x  5 sjl users   4096 Dec  2 12:12 bindings
drwxr-xr-x  7 sjl users   4096 Dec 21 19:06 build
drwxr-xr-x 13 sjl users   4096 Dec  2 12:12 cint
drwxr-xr-x  4 sjl users   4096 Dec  2 12:12 cmake
-rw-r--r--  1 sjl users   8465 Dec  2 12:12 CMakeLists.txt
drwxr-xr-x  2 sjl users   4096 Dec 21 19:06 config
-rw-r--r--  1 sjl users 297396 Dec 21 19:06 config.log
-rw-r--r--  1 sjl users    278 Dec 21 19:06 config.status
-rwxr-xr-x  1 sjl users 277179 Dec  2 12:12 configure
drwxr-xr-x 19 sjl users   4096 Dec  2 12:12 core
drwxr-xr-x 10 sjl users   4096 Dec  2 12:12 doc
drwxr-xr-x  8 sjl users   4096 Dec  2 12:12 documentation
drwxr-xr-x  9 sjl users   4096 Dec 21 19:06 etc
drwxr-xr-x  2 sjl users   4096 Dec  2 12:12 fonts
drwxr-xr-x  7 sjl users   4096 Dec  2 12:12 geom
drwxr-xr-x 18 sjl users   4096 Dec  2 12:12 graf2d
drwxr-xr-x 10 sjl users   4096 Dec  2 12:12 graf3d
drwxr-xr-x 12 sjl users   4096 Dec  2 12:12 gui
drwxr-xr-x  8 sjl users   4096 Dec  2 12:12 hist
drwxr-xr-x  5 sjl users   4096 Dec  2 12:12 html
drwxr-xr-x  2 sjl users  20480 Dec  2 12:12 icons
drwxr-xr-x 11 sjl users  65536 Dec 21 19:06 include
drwxr-xr-x 13 sjl users   4096 Dec  2 12:12 io
drwxr-xr-x  3 sjl users  20480 Dec 21 19:38 lib
-rw-r--r--  1 sjl users  26210 Dec  2 12:12 LICENSE
drwxr-xr-x  2 sjl users   4096 Dec 21 19:06 macros
drwxr-xr-x  3 sjl users   4096 Dec  2 12:12 main
-rw-r--r--  1 sjl users  53611 Dec 21 19:06 Makefile
drwxr-xr-x  3 sjl users   4096 Dec  2 12:12 man
drwxr-xr-x 21 sjl users   4096 Dec  2 12:12 math
drwxr-xr-x  8 sjl users   4096 Dec  2 12:12 misc
drwxr-xr-x  7 sjl users   4096 Dec  2 12:12 montecarlo
drwxr-xr-x 19 sjl users   4096 Dec  2 12:12 net
drwxr-xr-x 10 sjl users   4096 Dec  2 12:12 proof
drwxr-xr-x  2 sjl users   4096 Dec  2 12:12 README
drwxr-xr-x  7 sjl users   4096 Dec  2 12:12 roofit
drwxr-xr-x  3 sjl users   4096 Dec  2 12:12 rootx
drwxr-xr-x  9 sjl users   4096 Dec  2 12:12 sql                                                                                                              
drwxr-xr-x  9 sjl users   4096 Dec  2 12:12 test                                                                                                             
drwxr-xr-x  6 sjl users   4096 Dec  2 12:12 tmva                                                                                                             
drwxr-xr-x  6 sjl users   4096 Dec  2 12:12 tree                                                                                                             
drwxr-xr-x 43 sjl users   4096 Dec 22 14:18 tutorials   

I think I am completley misunderstanding you.

From your posts I understood that you have executable files ~/ROOT and ~/ROOT6.

The above shows that ~/ROOT is a directory containing the unpacked tarball.

Thus we have to start all over in understanding what you mean.
Not much time at the moment and it looks as I have to formulate some questions very thouroughfully to avoid further misunderstandings.

Will be back later.

Maybe this is the shortest way to a solution.

Please tell us exactly what you t type in the terminal to start the one version of that program and tell us what yoy want to type instead.

Please tell us exactly what you type in the terminal to start the other version of that program and tell us what you want to type instead.

in my .bashrc I have these lines dedicated for ROOT.
From people who built it I am instructed to use to load thisroot.sh


source ~/ROOT/thisroot.sh

but later I learned to change the system path for ROOT.


#Loading Root thisroot.sh in /HOME/ROOT/bin/thisroot.sh
export ROOTSYS=$HOME/ROOT/
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PAT

currently in order to launch ROOT5.34, with this .bashrc I only need to type

root

but if I want to launch ROOT 6.02. I type


source ~/ROOT6/thisroot.sh
root

sorry

/thisroot.sh

should be

~/ROOT/bin/thisroot.sh

and

~/ROOT6/bin/thisroot.sh

You do not show what is in there, thus how can I know?

May I assume that the above is the same as is in thisroot.sh

What happens now is that the PATH and LD_LIBRARY_PATH are extended at the beginning again. Thus when you switch several times in a session, those two will grow and grow!

The following alias statements could help:

alias root="ROOTSYS=$HOME/ROOT PATH=$ROOTSYS/bin:$PATH_LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH root"
alias root6="ROOTSYS=$HOME/ROOT6 PATH=$ROOTSYS/bin:$PATH_LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH root"

Both should of course be typed on one line!

Please try this out and report back.

I am currently recompiling ROOT6, it takes a few hours.
in ~/ROOT/bin/
I have:


~/ROOT/bin> ls -lttotal 1420
-rwxr-xr-x 1 sjl users  99487 Dec 21 19:38 hist2workspace
-rwxr-xr-x 1 sjl users  37073 Dec 21 19:38 h2root
-rwxr-xr-x 1 sjl users  28036 Dec 21 19:38 hadd
-rwxr-xr-x 1 sjl users 119182 Dec 21 19:38 pq2
-rwxr-xr-x 1 sjl users  37321 Dec 21 19:38 xpdtest
-rwxr-xr-x 1 sjl users  23827 Dec 21 19:38 roots.exe
-rwxr-xr-x 1 sjl users  23957 Dec 21 19:38 proofserv.exe
-rwxr-xr-x 1 sjl users  18580 Dec 21 19:37 root.exe
-rwxr-xr-x 1 sjl users  18567 Dec 21 19:37 rootn.exe
-rwxr-xr-x 1 sjl users 313939 Dec 21 19:30 rootcint
-rwxr-xr-x 1 sjl users  57304 Dec 21 19:29 g2root
-rwxr-xr-x 1 sjl users 184741 Dec 21 19:29 proofd
-rwxr-xr-x 1 sjl users  18300 Dec 21 19:29 ssh2rpd
-rwxr-xr-x 1 sjl users 207547 Dec 21 19:29 rootd
-rwxr-xr-x 1 sjl users  35780 Dec 21 19:29 genmap
-rwxr-xr-x 1 sjl users  39441 Dec 21 19:29 root
-rwxr-xr-x 1 sjl users  28450 Dec 21 19:29 rlibmap
-rwxr-xr-x 1 sjl users    821 Dec 21 19:28 roots
-rwxr-xr-x 1 sjl users   2868 Dec 21 19:28 proofserv
-rwxr-xr-x 1 sjl users   2078 Dec 21 19:28 prepareHistFactory
-rwxr-xr-x 1 sjl users  47991 Dec 21 19:06 rmkdepend
-rwxr-xr-x 1 sjl users     92 Dec 21 19:06 genreflex-rootcint
-rwxr-xr-x 1 sjl users    176 Dec 21 19:06 genreflex
-rw-r--r-- 1 sjl users   3834 Dec 21 19:06 setxrd.csh
-rwxr-xr-x 1 sjl users   3002 Dec 21 19:06 setxrd.sh
-rw-r--r-- 1 sjl users   5143 Dec 21 19:06 thisroot.csh
-rw-r--r-- 1 sjl users   3676 Dec 21 19:06 thisroot.sh
-rwxr-xr-x 1 sjl users   8447 Dec 21 19:06 memprobe
-rwxr-xr-x 1 sjl users  27231 Dec 21 19:06 root-config

I like your suggestion, but in my .bashrc

I modified


export ROOTSYS=$HOME/ROOT/
export PATH=$ROOTSYS/bin:$PATH

I’m curious if this would work, if I set up a dummy path such that

 
export ROOTSYS6=$HOME/ROOT6/
export PATH=$ROOTSYS/bin:$PATH

and within ROOT6/bin, replace all “root” executable with “root6”, would this technically work?

To begin with, I had to repair your CODE tags. When you click on the # button you get correct ones.

Second, it is not clear what you changed in your .bashrc. Post completely the before and after. Else nobody can guess what you added, changed, removed exactly.

Third, if it works what you do can you find out yourself: test it.

Fourth, I am unbable to decide what names within the ROOT6 tree must be changed. Remember that you set (and exported) a variable ROOTSYS. You now set ROOTSYS6, but I have no idea if the product uses SYSROOT anywhere. And when it does, it will point to the wrong product root. Same for the PATH variables. If you run a ROOT program which starts another ROOT program in a way that depends on PATH, then a ROOT6 version will be started when that specification comes first. Same (and mayby worse) for dynamic loaded libraries.

I gave a suggestion. You are not obliged to follow it, but then please say so. Then I can spend my free time for other problems here in the forums.

And my idea is that you do not realy understand what:

  • environment variables are;
  • how the PATH and LD_LIBRARY_PATH environment variables are used and thus should be managed.

You’re correct, my understanding on environmental variables/settings are limited.

My .bashrc did not have anything to do with ROOT, I wrote the following in myself after searching on google. I will get back to you after testing. I am still compiling. Thank you
-SJL

#Loading Root thisroot.sh in /HOME/ROOT/bin/thisroot.sh
export ROOTSYS=$HOME/ROOT/
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PAT

Hello, I copied ~/ROOT6/bin/root as root6then

I added this line to my .bashrc


alias root6="~/ROOT6/bin/root6"

so far this works to Open ROOT 6.02 but I am yet to test if it runs properly. I am unsure if it uses the proper library for operations either.

Also


alias root="ROOTSYS=$HOME/ROOT PATH=$ROOTSYS/bin:$PATH_LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH root"
alias root6="ROOTSYS=$HOME/ROOT6 PATH=$ROOTSYS/bin:$PATH_LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH root"

unfortunately did not work,

ROOT5 worked fine,
ROOT6 turned on ROOT5 and crash after freeze.

So far, for running macros and executables, everything seems to work well.

Can you shed some light about that code? I mean what does it suppose to do?

I am unsure now on what you did. Did you reverse all the name changes you did inside ROOT6?

My advice to do this was of course based on your ROOT and ROOT6 bing unaltered. But after I advised that, you came ack tellin that you changed named of ROOT6/bin/root and several other files there.

When I advice a and you in the meantime do b, c and d, the value of my advice becomes easily nullified.

I must add that I made a severe typing eror. In both cases there is an _ instead of a space betwwen the two asignments. The commands should read:

alias root="ROOTSYS=$HOME/ROOT PATH=$ROOTSYS/bin:$PATH $LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH $ROOTSYS/bin/root"

(in one line)
and

alias root6="ROOTSYS=$HOME/ROOT6 PATH=$ROOTSYS/bin:$PATH $LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH $ROOTSYS/bin/root"

(in one line)

And II assume it is better to add the full path to the command. But I do not have the product here and I asked you to test to enabble us to betttr those commandds with trial anderror. But you went on going different things. Thus this trial and error cycle takes more time.

Again, please try the above. It is btw not strange that root still functions with my trial, because you still have the old statments in your .bashrc. For the test it is better to comment them out for the moment.

I did try using the aliases you’ve suggested before I’ve made modifications.

Also, I “Copied” executable “~/ROOT6/bin/root” to root6, instead of renaming it. The changes should have been irrelevant even if I made modifications before testing.