Can we use PHP in Bash Script?

后端 未结 3 1910
攒了一身酷
攒了一身酷 2021-01-29 08:37

I have a bash script abcd.sh

#!/bin/sh
for i in `seq 8`; do ssh w$i \'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat\'; done &
pid=$!
sleep 1
ki         


        
3条回答
  •  星月不相逢
    2021-01-29 08:51

    It's not easy to understand what you want.

    Maybe this helps. The script defines a var PHP_VAR in bash and use this var in PHP. Then we call a PHP code snippet an put the output in the shell var output. At last we output the var output (but you can do something else with it).

    Attation: All the output from the PHP will be found in the var output.

    #!/bin/bash
    
    echo "I am a bash echo"
    
    export PHP_VAR="I was in php"
    # Here we start php and put the output in 'output'
    output=$(php << EOF
       
    EOF
    )
    
    # usage var 'output' with php output
    echo "---$output---"
    

提交回复
热议问题