Re: php variables in a backtick command

From: Date: Sun, 12 Dec 2004 04:35:29 +0000
Subject: Re: php variables in a backtick command
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-204087@lists.php.net to get a copy of this message
Ah, that is a good idea, putting the command in a variable and then executing the variable. I have doen that before but did not think of it now. Too many things going on. Thanks! Jonathan "Rory Browne" <rory.browne@gmail.com> wrote in message news:fa07888a04121118204f55784e@mail.gmail.com... > I'm not sure about variable expansion with backticks(I don't use > backticks, if necessary I use shell_exec() instead). I'm just after > installing a fresh SuSE 9.1, and php is giving me a segfault at the > minute, with that particular code, but if you were using double quotes > you could: > > $command = "adduser -l=$dist_id -p={$user['password']} > --f=\"{$user['name_first']} {$user['name_last']}\""; > > bearing in mind that the variables have been {}'ed, and your double > quote around $user['name_first'] and ['name_last']) has been escaped > to \" > > you can use shell_exec($command), which is identical to the backtick > operation. > > Having that said, you should consider using alternative program > execution instead, instead of using the shell. What do you need the > shell for? You might(albeit unlikely) also come across a situation > where the shell is something like /bin/false, or /bin/falselogin, or > /bin/scponly, or basicly something that doesn't particularly work that > well as a shell. > > Rory > > On Sat, 11 Dec 2004 18:09:17 -0700, Jonathan Duncan <jonathan@nacnud.com> > wrote: >> I am trying to run a shell command with backticks. However, I get a >> parse >> error. Is it because I have an array variable in there? >> >> $result = >> `adduser -l=$dist_id -p=$user['password'] --f="$user['name_first'] >> $user['name_last']"`; >> >> Do I need to assign the value to a regular variable before I put it in >> there? Like this? >> >> $pword=$user['password'] >> $fname =$user['name_first'] >> $lname =$user['name_last'] >> $result = adduser -l=$dist_id -p=$pword --f="$fname >> $lname"; >> >> Thanks, >> Jonathan >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>

« previous php.general (#204087) next »