Execute Script Using Alias
I am trying to create an alias that will execute a script. When I cd in the directory where the script is located ... lets say / usr / local / bin / startscript, then the script works as expected and starts the application I want.
SO. i went into my bashrc file and added alias startscript = '/ usr / local / bin / startscript'
The goal is to run the script by simply typing "startcript" from any directory.
However, when I try to use an alias to run the script, it doesn't work as expected, like the application that is supposed to run does not.
My script starts with
#!/bin/sh
and then from there
any ideas? Thanks to
SCRIPT:
#!/bin/sh
#- Check for user 'user'
if [[ "`whoami`" != "user" ]]; then
echo "This script can only be executed by user 'user'."; exit
fi
. /usr/local/bin/etctrx/startscriptdirectory/startscriptsetup
#- Kill manager to avoid multiple processes
pkill -f 'JavaApp.jar'
#- Start
nohup java -classpath /usr/local/bin/etctrx/startscriptdirectory/RequiredJars/ojdbc5.jar:/usr/local/bin/etctrx/startscriptdirectory/RequiredJars/activation.jar:/usr/local/bin/etctrx/startscriptdirectory/RequiredJars/mail.jar -jar /usr/local/bin/etctrx/startscriptdirectory/JavaApp.jar > ${JAVAAPPLOGS}/startscript.log 2>&1 &
source to share
If the script works as expected in / usr / local / bin by just typing startscript
, but the script is executed from another directory (does not return an error) but does not produce the desired results, then the problem is with the way you link to the application from the script ...
As others have pointed out, you don't need an alias for something in /usr/local/bin
, and if it runs from that directory, obviously your executable permissions are correct as well. If the application you are trying to run is also in /usr/local/bin
, then your script probably assumes it is in the same directory, which it would not be elsewhere, so you either need to ad a cd
to /usr/local/bin
within the script or give the full path of the application.
source to share
I can call the script if I do, but it still wont give me the results I want (the app starts up) as I do when I run the script from the directory it lives in.
It looks like the said "application" is in the same directory as the script /usr/local/bin
, which we have already installed on yours PATH
. For the script to work properly, but not the application, you may be calling the application incorrectly, like
./application
This will fail if you haven't called from /usr/local/bin
. The fix would be like this:
application
source to share