<SOLVED>Running a script from any directory?

Forum rules
Before you post please read how to get help
new_to_linux
Level 1
Level 1
Posts: 4
Joined: Mon Oct 14, 2013 5:57 am

<SOLVED>Running a script from any directory?

Postby new_to_linux » Sat Jul 15, 2017 7:09 pm

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 new_to_linux on Sun Jul 16, 2017 4:04 pm, edited 1 time in total.

User avatar
jimallyn
Level 16
Level 16
Posts: 6975
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Running a script from any directory?

Postby jimallyn » Sat Jul 15, 2017 7:24 pm

Image

“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 22
Level 22
Posts: 15636
Joined: Sat Dec 06, 2014 7:34 am

Re: Running a script from any directory?

Postby Cosmo. » Sun Jul 16, 2017 5:09 am

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
Level 1
Level 1
Posts: 4
Joined: Mon Oct 14, 2013 5:57 am

Re: Running a script from any directory?

Postby new_to_linux » Sun Jul 16, 2017 4:01 pm

Great answers! Thanks for the help!


Return to “Scripts & Bash”