RE: [PHP] PHP shell scripting..

From: Date: Sun, 22 Jul 2001 18:41:28 +0000
Subject: RE: [PHP] PHP shell scripting..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-59082@lists.php.net to get a copy of this message
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:ryan@devnut.com] > 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) ryan@devnut.com > (cell) 360-808-1506 > > > -----Original Message----- > > From: Kees Hoekzema [mailto:kees@tweakers.net] > > Sent: Sunday, July 22, 2001 11:27 AM > > To: Ryan Christensen; php-general@lists.php.net > > 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:ryan@devnut.com] > > > Sent: Sunday, July 22, 2001 8:19 PM > > > To: php-general@lists.php.net > > > 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: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: > > php-list-admin@lists.php.net > > > > > > > > > >

« previous php.general (#59082) next »