Dieses Blog durchsuchen

Sonntag, 14. Februar 2016

add a phpscript to .bashrc as an alias reboot save

Sometimes you want to add a phpscript to your linux enviroment, so that you can do something fancy on your shell console or even in a shell / bash script like:
ini-config -p all -a fancyparameter 

 The most common way to call a php script on the console is

/usr/bin/php /ugly/long/path/to/your/script.php -p all -a fancyparameter 

Noone wants to rember this path all the time.

The community tells me to put an alias in the ./bashrc. But that wont work, if you want to use your php script as a cmdtool in a shellscript without putting the path to the script in an echo like that:

echo "php /path/to/your/long/ugly/network/php/script.php -a all -p parameter"

You have to do some more.

The shellscripts become ugly and unmaintainable.
To get your phpscripts running as an alias cmdtool  you can just add an exportfunction to your ~/.bash_profile or ~/.bashrc and export this function instead of defining an alias, wich is deprecated, as I know.


now you can simlpy enter

fancyscript -p parametername

on your console.

The function in the ./bashrc is rebootsave, so, that you can use it after rebooting the whole wide world.




Keine Kommentare:

Kommentar veröffentlichen