Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1121  / 1 Year ago, fri, april 21, 2023, 1:29:37

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.


More From » bash

 Answers
5

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!


[#21166] Saturday, April 22, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
inciplyies

Total Points: 10
Total Questions: 114
Total Answers: 93

Location: French Polynesia
Member since Sun, Dec 20, 2020
3 Years ago
;