0

Running this in bash in my Homestead box works: symbRefHead=$(git symbolic-ref -q HEAD) && echo $symbRefHead && branch_name="${symbRefHead//refs\/heads\/}" && echo $branch_name

So why does running it via runLocally fail?

$options = ['tty' => true];
    runLocally('symbRefHead=$(git symbolic-ref -q HEAD) && echo $symbRefHead && branch_name="${symbRefHead//refs\/heads\/}" && echo $branch_name', $options);

I get this error:

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)

Similarly this version works in Bash but not in runLocally: symbRefHead=$(git symbolic-ref -q HEAD) && echo $symbRefHead && to_be_removed="refs/heads/" && branch_name="${symbRefHead/$to_be_removed/}" && echo $branch_name

I'm obviously trying to remove a substring from a string variable (search and replace with nothing) as mentioned here: https://unix.stackexchange.com/questions/104881/remove-particular-characters-from-a-variable-using-bash#comment437753_104887

P.S. Ultimately I'll want to be able to get the branch name into a variable so I can echo it here: https://stackoverflow.com/a/59689871/470749

3
  • 1
    The parameter substitution you are using is not a POSIX shell feature, but runLocally is executing sh rather than bash. Commented Feb 6, 2020 at 17:14
  • 1
    Why not just run git symbolic-ref -q HEAD with a subprocess and then do the output parsing withing php? Commented Feb 6, 2020 at 17:15
  • @jordanm Thank you for your hint about sh rather than bash! I don't understand your second comment. Thanks in advance. (You could post an answer.) Commented Feb 6, 2020 at 17:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.