[PHP] Php shell scripting
Does anyone know how I can pass variables into a script being executed from the command line? I have a script, named testscript. So far, I have been getting all my variables from the system env command, not a big deal. But I want to input a username into the script, like testscript jmchenry. In basic shell scripting, the value of any parameters would be $1, $2, $3, etc.. within the script, but how can I do this with PHP? Is it even possible? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Php shell scripting
$argv, possibly $_SERVER['argv']. Cheers, Rob. On Thu, 2003-12-11 at 00:31, Jake McHenry wrote: Does anyone know how I can pass variables into a script being executed from the command line? I have a script, named testscript. So far, I have been getting all my variables from the system env command, not a big deal. But I want to input a username into the script, like testscript jmchenry. In basic shell scripting, the value of any parameters would be $1, $2, $3, etc.. within the script, but how can I do this with PHP? Is it even possible? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Php shell scripting
On Thursday 11 December 2003 12:31 am, Jake McHenry wrote: Does anyone know how I can pass variables into a script being executed from the command line? I have a script, named testscript. So far, I have been getting all my variables from the system env command, not a big deal. But I want to input a username into the script, like testscript jmchenry. In basic shell scripting, the value of any parameters would be $1, $2, $3, etc.. within the script, but how can I do this with PHP? Is it even possible? var_dump($argv); Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- Evan Nemerson [EMAIL PROTECTED] http://coeusgroup.com/en -- They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. -Benjamin Franklin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Php shell scripting [SOLVED]
-Original Message- From: Evan Nemerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 9:32 PM To: Jake McHenry; [EMAIL PROTECTED] Subject: Re: [PHP] Php shell scripting On Thursday 11 December 2003 12:31 am, Jake McHenry wrote: Does anyone know how I can pass variables into a script being executed from the command line? I have a script, named testscript. So far, I have been getting all my variables from the system env command, not a big deal. But I want to input a username into the script, like testscript jmchenry. In basic shell scripting, the value of any parameters would be $1, $2, $3, etc.. within the script, but how can I do this with PHP? Is it even possible? var_dump($argv); Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- Evan Nemerson [EMAIL PROTECTED] http://coeusgroup.com/en -- They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. -Benjamin Franklin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Thanks for the very quick responses! Here's what I got from your responses: var_dump($argv); This returned NULL, so I tried: print_r($_SERVER['argv']); This returned exactly what I wanted. Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP shell scripting not working right?
I'm trying to do shell scripting in PHP. I have PHP installed in /usr/bin/php. I have the following script: #!/usr/bin/php -q ?php print Success!\n; ? It's saved as test.php and CHMODed to 777. When I type test.php at the command line, it says: bash: test.php: command not found When I type test, it acts like I just hit enter. Typing /usr/bin/php -q test.php does work. Does anyone know what I'm doing wrong? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP shell scripting not working right?
Ever answered your own question five seconds after asking it? Apparently, I have to type /path/to/test.php even though I'm already in the right directory. Leif K-Brooks wrote: I'm trying to do shell scripting in PHP. I have PHP installed in /usr/bin/php. I have the following script: #!/usr/bin/php -q ?php print Success!\n; ? It's saved as test.php and CHMODed to 777. When I type test.php at the command line, it says: bash: test.php: command not found When I type test, it acts like I just hit enter. Typing /usr/bin/php -q test.php does work. Does anyone know what I'm doing wrong? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP shell scripting not working right?
In Unix you need to specify the working folder when you are launching an executable, otherwise Bash will try to look into its search path, which does not include the current folder. Try: ./test.php That should work. BTW--running test by itself only *looks* like hitting enter--it's really a valid command. Try man test for more info. Cheers, Marco -- php|architect - The Magazine for PHP Professionals The monthly magazine dedicated to the world of PHP programming Check us out on the web at http://www.phparch.com! ---BeginMessage--- I'm trying to do shell scripting in PHP. I have PHP installed in /usr/bin/php. I have the following script: #!/usr/bin/php -q ?php print Success!\n; ? It's saved as test.php and CHMODed to 777. When I type test.php at the command line, it says: bash: test.php: command not found When I type test, it acts like I just hit enter. Typing /usr/bin/php -q test.php does work. Does anyone know what I'm doing wrong? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP shell scripting not working right?
You don't have ./ in your $PATH so you must type ./test.php to execute it Leif K-Brooks wrote: I'm trying to do shell scripting in PHP. I have PHP installed in /usr/bin/php. I have the following script: #!/usr/bin/php -q ?php print Success!\n; ? It's saved as test.php and CHMODed to 777. When I type test.php at the command line, it says: bash: test.php: command not found When I type test, it acts like I just hit enter. Typing /usr/bin/php -q test.php does work. Does anyone know what I'm doing wrong? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP shell scripting..
I have some questions about using PHP as a shell scripting language... mainly how you pass arguments to a script on the command line. Say I'm using: -- #!/usr/local/bin/php -q ? print I am: $name\n; ? -- How do I define test from the command line (as an argument while executing the script)? Thanks in advance for the help! - Ryan Christensen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] PHP shell scripting..
Hello Ryan, You can use environment variables for that, like: echo $HOME; /* Shows the HOME environment variable, if set. */ You can also use getenv() en putenv() see also: http://nl.php.net/manual/en/language.variables.external.php hope it works :) - Kees -Original Message- From: Ryan Christensen [mailto:[EMAIL PROTECTED]] Sent: Sunday, July 22, 2001 8:19 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP shell scripting.. I have some questions about using PHP as a shell scripting language... mainly how you pass arguments to a script on the command line. Say I'm using: -- #!/usr/local/bin/php -q ? print I am: $name\n; ? -- How do I define test from the command line (as an argument while executing the script)? Thanks in advance for the help! - Ryan Christensen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] PHP shell scripting..
Hello Ryan, Let me give you an example :) Lets use your script, #!/usr/local/bin/php -q ? print I am: $name\n; ? i called it echo-name.php and chmod 755 it. Next, im going to call it: -- Athena:~$ name=kees Athena:~$ ./echo-naam I am: kees -- So the trick is to set the variable BEFORE you call the script you can see all variables already used by linux with set you'll get something like this: -- Athena:~$ set BASH=/bin/bash BASH_VERSINFO=([0]=2 [1]=03 [2]=0 [3]=1 [4]=release [5]=i386-slackware-linux-gnu) BASH_VERSION='2.03.0(1)-release' COLUMNS=80 DIRSTACK=() (...snip...) TERM=xterm UID=1034 USER=kees _=./echo-naam file=/etc/profile.d/tetex.sh ignoreeof=10 name=kees - As you can see, our variable name is there, and it is set. to set a variable, simply type this at the commandline (or script) - variable=value --- where variable is your variable and value your value :) Good luck :) -Kees -Original Message- From: Ryan Christensen [mailto:[EMAIL PROTECTED]] Sent: Sunday, July 22, 2001 8:30 PM To: 'Kees Hoekzema' Subject: RE: [PHP] PHP shell scripting.. I'm slightly confused as to how I would run this from a shell though.. what would I enter in the command line then? - Ryan Christensen (mail) [EMAIL PROTECTED] (cell) 360-808-1506 -Original Message- From: Kees Hoekzema [mailto:[EMAIL PROTECTED]] Sent: Sunday, July 22, 2001 11:27 AM To: Ryan Christensen; [EMAIL PROTECTED] Subject: RE: [PHP] PHP shell scripting.. Hello Ryan, You can use environment variables for that, like: echo $HOME; /* Shows the HOME environment variable, if set. */ You can also use getenv() en putenv() see also: http://nl.php.net/manual/en/language.variables.external.php hope it works :) - Kees -Original Message- From: Ryan Christensen [mailto:[EMAIL PROTECTED]] Sent: Sunday, July 22, 2001 8:19 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP shell scripting.. I have some questions about using PHP as a shell scripting language... mainly how you pass arguments to a script on the command line. Say I'm using: -- #!/usr/local/bin/php -q ? print I am: $name\n; ? -- How do I define test from the command line (as an argument while executing the script)? Thanks in advance for the help! - Ryan Christensen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] PHP shell scripting..
Thanks.. that helps out a lot. Next question.. is there a way I can prompt for input? For example.. have a prompt Name: .. that waits for the user to enter their name.. and then assignes whatever they enter to a variable. Think you can help? :) Thanks... - Ryan Christensen -Original Message- From: Kees Hoekzema [mailto:[EMAIL PROTECTED]] Sent: Sunday, July 22, 2001 11:41 AM To: Ryan Christensen Cc: [EMAIL PROTECTED] Subject: RE: [PHP] PHP shell scripting.. Hello Ryan, Let me give you an example :) Lets use your script, #!/usr/local/bin/php -q ? print I am: $name\n; ? i called it echo-name.php and chmod 755 it. Next, im going to call it: -- Athena:~$ name=kees Athena:~$ ./echo-naam I am: kees -- So the trick is to set the variable BEFORE you call the script you can see all variables already used by linux with set you'll get something like this: -- Athena:~$ set BASH=/bin/bash BASH_VERSINFO=([0]=2 [1]=03 [2]=0 [3]=1 [4]=release [5]=i386-slackware-linux-gnu) BASH_VERSION='2.03.0(1)-release' COLUMNS=80 DIRSTACK=() (...snip...) TERM=xterm UID=1034 USER=kees _=./echo-naam file=/etc/profile.d/tetex.sh ignoreeof=10 name=kees - As you can see, our variable name is there, and it is set. to set a variable, simply type this at the commandline (or script) - variable=value --- where variable is your variable and value your value :) Good luck :) -Kees -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]