0% found this document useful (0 votes)
14 views3 pages

Pass PHP Variables To A Bash Script and Then Launch It

The document discusses how to pass PHP variables to a Bash script for execution. It presents two options: passing parameters directly to the script or using environment variables to set the values. The examples provided illustrate how to implement both methods effectively.

Uploaded by

syb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Pass PHP Variables To A Bash Script and Then Launch It

The document discusses how to pass PHP variables to a Bash script for execution. It presents two options: passing parameters directly to the script or using environment variables to set the values. The examples provided illustrate how to implement both methods effectively.

Uploaded by

syb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Pass PHP variables to a Bash script and then launch it

stackoverflow.com /questions/13903506/pass-php-variables-to-a-bash-script-and-then-launch-it

Learn, Share, Build


Each month, over 50 million developers come to Stack Overflow to learn, share their knowledge, and build their
careers.

Join the world’s largest developer community.

Google

Facebook

or

So, basically, what I want to do is execute this Bash script :

#!/bin/bash

path="./"
filename="Ellly.blend"
file=${path}${filename}
description="Test of the api with a simple model"
token_api="ff00ff"
title="Uber Glasses"
tags="test collada glasses"
private=1
password="Tr0b4dor&3"

curl -k -X POST -F "fileModel=@${file}" -F "filenameModel=${filename}" -F


"title=${title}" -F "description=${description}" -F "tags=${tags}" -F
"private=${private}" -F "password=${password}" -F "token=${token_api}"
https://api.sketchfab.com/v1/models

Inside a PHP function. Problem is, I don't really see how I can pass to it some variables and then wait for it
to end before resuming the PHP function.

Any help ?

php bash

asked Dec 16 '12 at 17:05

Axiol

1,67152534

1 Answer

1/3
up vote 13 down vote Note: I didn't do all the settings, just enough I hope you get the idea.
accepted
Option 1: Passing parameters

PHP:

$output = exec("./bashscript $file $filename $tags $private


$password");

#!/bin/bash

Bash:

filename=$1
file=$2
description="Test of the api with a simple
model"
token_api="ff00ff"
title="Uber Glasses"
tags=$3
private=$4
password=$5

...

Option 2: Using environment variables

PHP:

putenv("FILENAME=$filename");
putenv("FILE=$file");
putenv("TAGS=$tags");
putenv("PRIVATE=$private");
putenv("PASSWORD=$PASSWORD");

$output = exec('./bash_script');

Bash:

filename=$FILENAME
file=$FILE
description="Test of the api with a simple
model"
token_api="ff00ff"
title="Uber Glasses"
tags=$TAGS
private=$PRIVATE
password=$PASSWORD

...

2/3
answered Dec 16 '12 at 17:20

Levi Morrison

14.3k44367

Your Answer

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged php bash or
ask your own question.

3/3

You might also like