There's couple things you need to keep in mind:
bash
accepts a script file as argument, which is what bash trimmomatic
does, however bash trimmomatic
implies that the file trimmomatic
has to be in the current working directory where you execute the command bash trimmomatic
. Command-line parameters which are files, unless specified with full path, have to be in current working directory.
When you execute any non-builtin command in shell, such as ls
or df
, the shell goes through list of directories in $PATH
variable. If a file is found and is executable in any of those directories, then the shell will execute it. Of course, ~/Desktop
is not on the list of directories in $PATH
, so you cannot call it directly as trimmomatic
Now, you have a single-line script. Practically speaking, a full script is unnecessary in case where you have just a single command there, unless it is intended to be shared with other users on the system. A far more practical way, would be to define an alias or a function in your ~/.bashrc
file. For a function, you can do
trimmomatic(){
java -jar /home/aishah/software_library/Trimmomatic-0.36/trimmomatic-0.36.jar
}
After you append this to ~/.bashrc
, run source ~/.bashrc
command, and the function can be called as
$ trimmomatic
Functions don't depend on $PATH
, hence you can execute them anywhere. If you do insist on using a script, then I would suggest placing the script into ~/bin
directory or ~/.local/bin
. On Ubuntu ~/bin
is added to $PATH
when you sign in through ~/.profile
config file, however ~/.local/bin
is not, so you would have to add the following line to your ~/.bashrc
file: PATH="$PATH:~/.local/bin
. In both cases remember to source config file to update your current shell environment. Once that is done, the shell will start looking in either of those directories, and if your script is located there, it will be executed. Of course, this way you don't need to call the script via bash trimmomatic
, rather you can call trimmomatic
directly.
source ~/.bashrc
. If you update that file, changes won't affect the shell unless you run that command – Sergiy Kolodyazhnyy Feb 04 '19 at 03:23