I am trying to run a function from a php file and run it from cli without having to type php deploy so have added a shebang so the cli knows how to run the script.

Misalnya

#!/usr/bin/env php
<?php

if (PHP_SAPI !== 'cli') {
  echo 'bin/deployer must be run as a CLI application' . "\n";
  exit(1);
}

function deploy(){
  echo "Deploying" . "\n";
}

foreach ($argv AS $arg){
  function_exists($arg) AND call_user_func($arg);
}

File: deployer

This does work fine from root directory and running bin/deployer deploy works as expected. I'm just curious as to why if run from the directory bin: deployer deploy i get -bash: deployer: command not found

0
harri 15 November 2017, 15:32

1 menjawab

Jawaban Terbaik

Coba ini di dalam direktori bin/:

./deployer deploy

If you omit the ./ in front of your file, your shell will look for the command deployer in your path ($PATH), instead of treating it as a path to the file to execute.

The $PATH is a list of directories, where your shell will look for the command you typed. To see what is in your path, try:

echo $PATH
1
C0DY 15 November 2017, 12:48