<SOLVED>Running a script from any directory?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
new_to_linux

<SOLVED>Running a script from any directory?

Post by new_to_linux »

Hello, I'm just starting out with Linux and I'm trying to write a simple script for initializing a program.

So far, this is what I've got and it executes fine:

#!/bin/bash
clear
cd /
cd home/albatros/Programs/pycharm/bin
./pycharm.sh

To execute it, I have to first go to the directory where the script is placed.

However, is there a way to execute it from any directory I'm currently working in?

Cheers and thanks for the help!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Running a script from any directory?

Post by jimallyn »

“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: Running a script from any directory?

Post by Cosmo. »

Create in your home the folder bin and move the script into it. After the next log in into your account this folder will be automatically added to the PATH.
new_to_linux

Re: Running a script from any directory?

Post by new_to_linux »

Great answers! Thanks for the help!
Locked

Return to “Scripts & Bash”