在 bash 脚本中使用 php 脚本的输出
Using the output of a php script in a bash script
我有一个有效的 .bash_profile 启动脚本,如下所示:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/bin
export PATH
while true;
do
./xxx.php
echo "Program Restarting."
sleep 10
done
我需要对其进行编辑,以便根据 xxx.php 脚本的退出方式(可能使用 exit(1)),脚本“跳出”其永久循环,并实际退出 shell 它在(应该关闭我正在使用的设备上的 Putty window)。
问题是,我不知道 shell 脚本,所以我似乎无法获得正确的语法。
正在尝试
if [./xxx.php]; then
exit
fi
给我“-bash: [./xxx.php]: 没有这样的文件或目录”(如果我只是输入“xxx.php,我会得到同样的错误信息" 或 "/home/user/xxx.php")
的完整路径
正在尝试将返回的代码保存在变量中供以后使用ala
BreakVar = $(./xxx.php)
只会导致腻子 window 冻结。
我试过阅读
中的问题
Run PHP function inside Bash (and keep the return in a bash variable)
或
How can I assign the output of a function to a variable using bash?
也对我帮助不大,因为我不明白具体的语法是如何工作的,所以我无法将这些答案转换为我的具体情况。
注意:除了向 xxx.php 脚本添加简短的“exit(1)”子句外,假设我不允许进一步更改该脚本:(.
退出状态一般通过变量$?获取。参见 here。所以,假设你想在退出状态为1时退出循环,你写
while true;
do
./xxx.php
if [ $? -eq 1 ]
then
break
fi
done
我有一个有效的 .bash_profile 启动脚本,如下所示:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/bin
export PATH
while true;
do
./xxx.php
echo "Program Restarting."
sleep 10
done
我需要对其进行编辑,以便根据 xxx.php 脚本的退出方式(可能使用 exit(1)),脚本“跳出”其永久循环,并实际退出 shell 它在(应该关闭我正在使用的设备上的 Putty window)。
问题是,我不知道 shell 脚本,所以我似乎无法获得正确的语法。
正在尝试
if [./xxx.php]; then
exit
fi
给我“-bash: [./xxx.php]: 没有这样的文件或目录”(如果我只是输入“xxx.php,我会得到同样的错误信息" 或 "/home/user/xxx.php")
的完整路径正在尝试将返回的代码保存在变量中供以后使用ala
BreakVar = $(./xxx.php)
只会导致腻子 window 冻结。
我试过阅读
中的问题Run PHP function inside Bash (and keep the return in a bash variable)
或
How can I assign the output of a function to a variable using bash?
也对我帮助不大,因为我不明白具体的语法是如何工作的,所以我无法将这些答案转换为我的具体情况。
注意:除了向 xxx.php 脚本添加简短的“exit(1)”子句外,假设我不允许进一步更改该脚本:(.
退出状态一般通过变量$?获取。参见 here。所以,假设你想在退出状态为1时退出循环,你写
while true;
do
./xxx.php
if [ $? -eq 1 ]
then
break
fi
done