How to rotate a bash file "mytest.sh" to a MAC without using "./", using aliases and in a global way?

0

I have a mytest.sh file that will be distributed among other users (all with mac). I want to know what has to be done so they can run the script from this file, from anywhere (in a global way) without having to use ./ and sweating only an alias, runtest ?     

asked by anonymous 20.11.2017 / 17:11

2 answers

3

You have two alternatives.

First: Add the directory that your script is located in the PATH variable to make it easier to run

PATH=$PATH:~/opt/bin:~/dev/bin:/seu/diretorio/

So you just have to type the name of your script from whatever directory you are in.

Second: Create an alias, as you yourself suggested.

alias NomeDoAlias='/seu/diretorio/script.sh'

This will require you to enter only the name of your Alias on the command line.

The two commands can be added to the / etc / profile file, because every user logging in will load those settings.

    
20.11.2017 / 21:56
1

Here are two orthogonal questions:

  • To avoid sudo cp script /usr/local/bin , we can merge the current folder to PATH

export PATH=$PATH:.

(possibly add this line to the file cp script ~/bin to be activated each time we log in)

The second option is great for personal machines but should be avoided if we work on a hostile machine (example if we are an administrator system with users who like to try to arm commands ...)

    
29.11.2017 / 13:24