0

I'm trying to create a shortcut that will run a .sh file deep in some directory without having to navigating to the absolute path.

I have tried using aliases, which did not work as. Using soft/hard links, they did not work too as there are certain dependencies in that directory which the shell script reference to.

Anyone has any idea how to ./ a file without having to traverse down that absolute path?

The alias I have tried is :

alias minecraft='/var/www/owncloud/data/admin/files/Spigot/start.sh'

I have tried the Path variant by adding PATH=/var/www/owncloud/data/admin/files/Spigot:"$PATH" into ~/.bashrc.

Which then brings the message :

Error: Unable to access jarfile spigot.jar

I'm using a cli version of Ubuntu if it helps, so no Nautilus.

muru
  • 207,228

3 Answers3

1

You didn't setup your alias correctly, you should setup it like so: alias minecraft='sh /var/www/owncloud/data/admin/files/Spigot/start.sh'

kos
  • 41,268
1

You are getting the

Error: Unable to access jarfile spigot.jar

Errormessage because the script are using your bash environment working directory when it is executing. The script is probably executing java -jar spigot.jar where spigot.jar file must reside in the same directory. Since youre scripts environment is pointing at another directory the file cannot be found.

To fix this, edit your /var/www/owncloud/data/admin/files/Spigot/start.sh file and add this line just above the command where it is executing java.

cd "$( dirname "${BASH_SOURCE[0]}" )"

This command changes the current executing directory for the script to the directory it resides.

The result should be something like:

 #!/bin/bash

 cd "$( dirname "${BASH_SOURCE[0]}" )"
 java -jar spigot.jar

Then you can use the alias you mentioned in your question, or probably along with many of the other answers that is here.

Good luck!

stalet
  • 589
0

To get rid of the "./" expression for your script, You must have to set the custom path for your scripts in PATH variable. You can do it either using the export Command ( which will set up the variable under current running environment) or as below (for permanent solution)

To do so; Edit the .bashrc file in your home directory with your favorite Editor

vi .bashrc

at the end of the file you can paste the following code.

#custom variable
export PATH=$PATH:/$HOME/bin:/var/www/owncloud/data/admin/files/Spigot/

Above command sets up the additonal paths for your script file location, in this case your .sh script in Spigot folder.

One thing you must remember while exporting the path is either you have to copy the contents of existing PATH variable into a file or in a text file using other editor you can do echo $PATH >> variables.txt

Reason why I'm saying so is if in case you lost the variable path, you wont be able to run other commands at all with aliases.

Finally: type exec bash

I have tested it hope it works fine for you as well. You should also be able to run the script without typing the full path. It should work as start.sh

Good Luck!