Pass PHP variables to a Bash script and then launch it

后端 未结 1 1670
遇见更好的自我
遇见更好的自我 2020-12-08 22:17

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

#!/bin/bash

path=\"./\"
filename=\"Ellly.blend\"
file=${path}${filename}
description=\"Test o         


        
相关标签:
1条回答
  • 2020-12-08 23:17

    Note: I didn't do all the settings, just enough I hope you get the idea.

    Option 1: Passing parameters

    PHP:

    $file = escapeshellarg($file);
    $filename = escapeshellarg($filename);
    // escape the others
    $output = exec("./bashscript $file $filename $tags $private $password");
    

    Bash:

    #!/bin/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
    
    ...
    
    0 讨论(0)
提交回复
热议问题