Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP vs BASH for CLI scripting? [closed]

I have never used PHP with CLI, but I have seen scripts running with PHP code.

I was wondering:

  • Why should we use BASH, when PHP is so popular and is able to run in CLI?
  • What are the pros and cons with each one?
  • Should I use PHP for all CLI scripting in the future?
like image 717
never_had_a_name Avatar asked May 06 '10 23:05

never_had_a_name


2 Answers

Bash is more common for this type of application, simply by virtue of it being around forever. But when it comes to choosing one over the other. The language you already know is usually the better choice. Just because you will be more productive.

like image 181
Steve Robillard Avatar answered Sep 26 '22 06:09

Steve Robillard


I guess the main thing is: bash is always there on a recent unix system (its predecessors really are always there, even on ancient unixen). Bash uses every little utility on the system, which can include PHP, Python, Ruby, AWK, Perl (those last two especially).

Consider: how do you get PHP installed? Bunch of bash scripts and a makefile, right? Or your OS package manager, which these days is probably Python, but used to be a bash script as well.

You can't administer unix without knowing the shell really well, nor can you write or use makefiles. It may not be the right answer every time, but for a scripting job I always try to figure out if it can be done in bash first.

like image 33
Andrew McGregor Avatar answered Sep 23 '22 06:09

Andrew McGregor