在Bash中运行PHP函数(并将返回值保存在bash变量中)

栏目: PHP · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/6231991/run-php-function-inside-bash-and-keep-the-return-in-a-bash-variable
我试图在Bash中运行 PHP

函数…但它无法正常工作.

#! /bin/bash

/usr/bin/php << 'EOF'
<?php echo getcwd(); ?>
EOF

在现实中,我需要将返回值保存在bash变量中……顺便说一下,我使用 php 的getcwd()函数来说明bash操作.

更新:有没有办法传递变量?

VAR='/$#'
php_cwd=`/usr/bin/php << 'EOF'
<?php echo preg_quote($VAR); ?>
EOF`
echo "$php_cwd"

有任何想法吗?

php_cwd=`/usr/bin/php << 'EOF'
<?php echo getcwd(); ?>
EOF`
echo "$php_cwd" # Or do something else with it

翻译自:https://stackoverflow.com/questions/6231991/run-php-function-inside-bash-and-keep-the-return-in-a-bash-variable


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Creative Curve

The Creative Curve

Allen Gannett / Knopf Doubleday Publishing Group / 2018-6-12

Big data entrepreneur Allen Gannett overturns the mythology around creative genius, and reveals the science and secrets behind achieving breakout commercial success in any field. We have been s......一起来看看 《The Creative Curve》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具