From 6509b7fc286262b61d740b765134a3f42362dbc6 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Fri, 10 May 2002 22:08:56 +0000 Subject: [PATCH] - minor improvements # Nice work Markus! git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@81712 c90b9560-bf6c-de11-be94-00142212c4b1 --- features/commandline.xml | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/features/commandline.xml b/features/commandline.xml index 9b26779ba6..49b39fb202 100644 --- a/features/commandline.xml +++ b/features/commandline.xml @@ -1,5 +1,5 @@ - + Using PHP from the command line @@ -148,7 +148,7 @@ $ php -f another_directory/test.php /tmp ]]> - This allows for greater flexibility when writing shell tools in + This allows greater flexibility when writing shell tools in PHP. @@ -229,7 +229,7 @@ php -r 'print_r(get_defined_constants());' - Read the example carefully, thera are no beginning or end tags! The + Read the example carefully, thera are no beginning or ending tags! The -r switch simply does not need them. Using them will lead to a parser error. @@ -237,7 +237,7 @@ php -r 'print_r(get_defined_constants());' - Provide the PHP code to execute via standard input + Provide the PHP code to execute via standard input (stdin). @@ -259,7 +259,7 @@ $ some_application | some_filter | php | sort -u >final_output.txt accepts a number of arguments but also your PHP script can receive them. The number of arguments which can be passed to your script is not limited by PHP (the shell has a certain size limit - in numbers of characters which can be passed, usually you won't hit this + in numbers of characters which can be passed; usually you won't hit this limit). The arguments passed to your script are available in the global array $argv. The zero index always contains the script name (which is - in case the PHP code @@ -271,11 +271,11 @@ $ some_application | some_filter | php | sort -u >final_output.txt As long as the arguments you want to pass to your script do not start with - the - character, there's nothing special to whatch out + the - character, there's nothing special to watch out for. Passing an argument to your script which starts with a - will cause trouble because PHP thinks it has to handle it. To prevent this use the argument list separator - --. After argument has been parsed by + --. After the argument has been parsed by PHP, every argument following it is passed untoched/unparsed to your script. @@ -297,8 +297,8 @@ array(2) { ]]> - But, there's another way of using PHP for shell - scripting. You can write a script whose first line starts with + However, there's another way of using PHP for shell + scripting. You can write a script which's first line starts with #!/usr/bin/php and then following the normal PHP code included within the PHP starting and end tags and set the execution attributes of the file @@ -393,11 +393,13 @@ array(4) { -v - Writes the PHP and Zend version to standard output, e.g. + Writes the PHP, PHP SAPI, and Zend version to standard output, e.g. + @@ -410,9 +412,11 @@ Zend Engine v1.2.1, Copyright (c) 1998-2002 Zend Technologies &php.ini; or you can specify a custom INI file directly (which does not need to be named &php.ini;), e.g.: + @@ -481,9 +485,9 @@ string(15) "doesntmakesense" Load Zend extension. If only a filename is given, PHP tries to load this extension from the current default library path on your system - (usually specified /etc/ld.so.conf on Unix + (usually specified /etc/ld.so.conf on Linux systems). Passing a filename with an absolute path information will - not use the systems library search path. A relative filename with a + not use the systems library search path. A relative filename with a directory information will tell PHP only to try to load the extension relative to the current directory. @@ -521,6 +525,7 @@ string(15) "doesntmakesense" Using this option, PHP prints out the built in (and loaded) PHP and Zend modules: + @@ -575,7 +580,7 @@ $ php -r "$foo = get_defined_constants();" Command line code(1) : Parse error - parse error, unexpected '=' ]]> - The problem here is that the shell performs variable substritution + The problem here is that the sh/bash performs variable substritution even when using double quotes ". Since the variable $foo is unlikely to be defined, it expands to nothing which results in being the code passed to @@ -586,8 +591,8 @@ $ php -r " = get_defined_constants();" ]]> The correct way would be to use single quotes '. - The shell doesn't expand variables in strings quoted with single - quotes: + variables in strings quoted with single quotes are not expanded + by sh/bash. + If you are using a shell different from sh/bash, you might experience + further issues. Feel free to open a bug report or send a mail to + phpdoc@lists.php.net. + One still can easily run intro troubles when trying to get shell variables into the code or using backslashes for escaping. You've been warned.