Sunday, May 5, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2354  / 1 Year ago, sun, january 22, 2023, 2:03:27

I have an application that I can run while I am in the file location as the below:


-$ cd home/myApps/app
-$ ./run.sh

I want to call the run.sh from anywhere in my terminal without being in the full path, I tried to used alais and add the below code to bashrc file.


alias mylovleyapp=/home/myApps/app/run.sh

the problem is whenever I want to run the app using mylovleyapp, the program return error because the run.sh is depending on another files in myApps folder


How I can achieve that?


More From » command-line

 Answers
5

There are many ways to Rome.


Alias


If you prefer an alias, you can as follows:


alias mylovleyapp='(cd home/myApps/app && ./run.sh)'

The braces (...) cause the two commands to run in a subshell. Thus, your current directory will not have changed once the program has ended.


A wrapper script in your PATH


Instead, you can create a wrapper script and place that in a folder that is in your search PATH, e.g. ~/.local/bin or ~/bin if you are the only user needing access, or /usr/local/bin if all users need access. Then all you need to do is type the name of the script to launch the program.


The script can be just what you normally do to start the program:


#!/usr/bin/env bash
cd home/myApps/app
./run.sh

Save that script for example as ~/.local/bin/mylovleyapp. Make the script executable so it can be run:


chmod +x ~/.local/bin/mylovleyapp

If ~/.local/bin did not exist, and you had to create it, then log out and then back in to have it automatically included in your PATH. From now on, just typing mylovleyapp in the terminal will run your app.


[#1124] Monday, January 23, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ngthmated

Total Points: 12
Total Questions: 115
Total Answers: 113

Location: Saint Vincent and the Grenadines
Member since Wed, Apr 21, 2021
3 Years ago
ngthmated questions
Mon, Nov 1, 21, 17:58, 3 Years ago
Tue, Jan 10, 23, 00:45, 1 Year ago
Tue, Nov 15, 22, 23:22, 2 Years ago
;