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