在我的 Homestead 盒子中以 bash 运行它可以:symbRefHead=$(git symbolic-ref -q HEAD) && echo $symbRefHead && branch_name="${symbRefHead//refs\/heads\/}" && echo $branch_name
那么为什么通过 runLocally 运行它会失败呢?
$options = ['tty' => true];
runLocally('symbRefHead=$(git symbolic-ref -q HEAD) && echo $symbRefHead && branch_name="${symbRefHead//refs\/heads\/}" && echo $branch_name', $options);
我收到此错误:
sh: 1: Bad substitution
In Process.php line 250:
The command "symbRefHead=$(git symbolic-ref -q HEAD) && echo $symbRefHead && branch_name="${symbRefHead//refs\/heads\/}" && echo $branch_name" failed.
Exit Code: 2(Misuse of shell builtins)
同样,此版本适用于 Bash,但不适用于 runLocally:symbRefHead=$(git symbolic-ref -q HEAD) && echo $symbRefHead && to_be_removed="refs/heads/" && branch_name="${symbRefHead/$to_be_removed/}" && echo $branch_name
我显然试图从字符串变量中删除子字符串(搜索并替换为空),如此处所述:https ://unix.stackexchange.com/questions/104881/remove-particular-characters-from-a-variable-使用-bash#comment437753_104887
PS最终我希望能够将分支名称转换为变量,以便我可以在这里回显它:https ://stackoverflow.com/a/59689871/470749