0

It's boring to run java commande using java -jar arg1 arg2 .. Is there a way to create a standard command line easily from a script file, without alias ?
For instance using /usr/bin/trimmomatic to replace

java -jar /PROGS/EXTERN/trimmomatic-0.35.jar MYFILE 

by

trimmomatic MYFILE
dridk
  • 180
  • 2
  • 13
  • Please see what does an `alias` does in `bash` http://tldp.org/LDP/abs/html/aliases.html – Inian Sep 21 '16 at 13:47
  • There are multiple answers on SO for similar questions, like this http://stackoverflow.com/questions/12397508/creating-an-alias-in-ubuntu-in-profile and this http://stackoverflow.com/questions/19647744/how-to-create-a-permanent-alias-for-ubuntu – Inian Sep 21 '16 at 13:49
  • I wasn't clear sorry. I m asking if it's possible to do this using a bash script file. For instance /usr/bin/trimmomatic – dridk Sep 21 '16 at 13:57

1 Answers1

0

You can append the following to your ~/.bashrc file:

alias trimmomatic='java -jar /PROGS/EXTERN/trimmomatic-0.35.jar'

Then restart your shell (or do source ~/.bashrc if you don't want to restart it) and the alias should be available.

Alternatively, you can define a bash function (e.g. in your ~/.bashrc again):

trimmomatic() { java -jar /PROGS/EXTERN/trimmomatic-0.35.jar "$@"; }

or a wrapper shell script that you can put in you $PATH:

#!/bin/bash
java -jar /PROGS/EXTERN/trimmomatic-0.35.jar "$@"
redneb
  • 21,794
  • 6
  • 42
  • 54
  • Thanks I know about alias. I was thinking about a file into the bin folder PATH. – dridk Sep 21 '16 at 13:56
  • That won't work, `$PATH` is only for native executables/scripts, not for `jar` files. – redneb Sep 21 '16 at 13:58
  • @dridk See my updated answer for the other alternatives. – redneb Sep 21 '16 at 14:00
  • yes, but it's possible to run Python script . Why the shebang #!/bin/java -jar doesn't exist ? – dridk Sep 21 '16 at 14:01
  • @dridk The shebang must be part of the file to be executed (the jar file in this case). If jar files did start with the string `#!/bin/java -jar\n`, then you would just `chmod +x` and execute like you do with standard executables. Unfortunately for you, this is not the case, so you cannot do that. – redneb Sep 21 '16 at 14:06