Script to system default... oO

Sorry, I don’t know how to call this topic :slight_smile:

So, I have a lot of my own Perl scripts, but it’s very difficult to call em… How to make em like system default or…

For example, my “calc.pl” script is calling like this -

./calc.pl 1 + 1 … and for it you need to start your Terminal from root dir, where script is…

And how to make, that I could call it from everywhere, like this - “calc 1 + 1”…

understand?.. To make “calc” like system name… or… so, hope you understand :slight_smile:

When I understand you correct you do want to call your scripts by name from anywhere and not by providing the path to the script like:

./script

when you are in the directory where the script is, or

/home/yourusername/scriptdir/script 

when your working directory is somewhere else,
but just do

script

Correct? For this the path to your script must be in your PATH environment variable. To see what is in your PATH now, do:

echo ${PATH}

To add a directory do:

PATH="${PATH}:<scriptdir>"

where is the directory (absolute, starting with /) where your script reside.
Normale the directory bin in your home directory is a good place to use. So:

PATH="${PATH}:/home/yourusername/bin"

is then what should be added.
Check the PATH by doing

echo ${PATH}

again.

Now you do not want to do this every time you go to a terminal. So add the line to your .bashrc, it will then be executed every time you start bash.

PS Many people will not use the {…} around the variable name, but I prefer this notation.

/home/a_name/bin is already in a_name’s path.

Oh, God, so easy :slight_smile: … Yeah, you right… Thanks a lot, it really works :slight_smile:

But what with .bashrc? I don’t get it…

@swerdna: of course, I should have mentioned that.

@Ru_Nez: in your home directory there is a file named .bashrc (mind the . ).
It is executed when you start bash, thus also when you open a terminal with bash inside. In this file you can place statements you want to be executed at that moment in time.

So edit .bashrc and add the statement PATH="…" to it.

Check by opening a new terminal and echo $PATH.

Or, just move your script into the bin directory. As swerdna already pointed out, you do not need to change PATH in that case because $HOME/bin is already there.

I know about this file… Just to add PATH string to the end of file?.. Ok, I’ll try that :slight_smile:

Thanks a lot, no problems or questions now :slight_smile:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Or if you do not want to move your script just create a symlink to the
script and place that symlink in ~/bin (~ == your home directory).

Good luck.

hcvv wrote:
> @swerdna: of course, I should have mentioned that.
>
> @Ru_Nez: in your home directory there is a file named .bashrc (mind the
> . ).
> It is executed when you start bash, thus also when you open a terminal
> with bash inside. In this file you can place statements you want to be
> executed at that moment in time.
>
> So edit .bashrc and add the statement PATH="…" to it.
>
> Check by opening a new terminal and echo $PATH.
>
> Or, just move your script into the bin directory. As swerdna already
> pointed out, you do not need to change PATH in that case because
> $HOME/bin is already there.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJyNMFAAoJEF+XTK08PnB58r0P/14gf1SMJNouqNxRmBIITaVw
8IscgHdpb5ubMcpkXsJ7JaHuOImccR2bSl+CW6bZHNlee1PjDssWnLU1fOjfkr3U
kKxsz/mzi5QIpGcPlNUr8nSseVUux/qj1a7mOnixeh5Eiid6rks0k7eXSNrudA2q
n7K2pI1pjbIJeWAi9eVc4Y1hlsihxtFU45cRVWMOZZy0FA2cpdwVSM0qgQFd4Kvt
2Rl5yM9u6ruKUdZvmUm5brAFU08xqYpcGpMmBdZtnRUpg4UAfAey6nWbXjnDTker
i4Hm/toPqOHp0nzmYxQCoPUix5wCFwbEsc0XR435pRgALB9TbbQ884YxuLSJfI9R
+i+zbjpyWIFlgazn0N78E3+eAObax/eYPbyRsYqMc6Txl1CRv0Z+3gy/smLiTvOW
eZj5j+7wqJfgD16Yyew3NxbGsdZ1QC2LHrbqOtGebc2uloBSq4QsxPDPm/rOH4Wf
7DRisz5PLnQzjAtjINOgP8hrEalZv1aLv2yb5YzI36+35oGYfSaKQNZIQInT3UeG
CoFZ69Q9+ZfmKFfIVYbYieNNzZP2U3CVoLgbiqRSpm+QN3UYc2Twt7IpGQ4jO+st
epCI9zLJkx4TBVgY4kCM/U7BXx4/P0QzxJAmP0l0uvkzEgYheljDNLss2TRWb5l+
17OxkzU9YoRQDm7eZI4F
=pq2C
-----END PGP SIGNATURE-----