All Bash function commands work besides a PHP Composer command

I use the following code to upgrade my website's content management system Drupal.

I have putted the following code in my .bashrc file in a function which is exported to all shell sessions but for some reason all function commands work besides the first, a PHP Composer command.

export -f drupal_upgrade

drupal_upgrade() {
	composer show drupal/core --latest | grep 'latest'
	vendor/bin/drush status # Validate current Drupal version
	chmod u+w web/sites/default
	composer update
	vendor/bin/drush updatedb
	vendor/bin/drush cache:rebuild
	chmod u-w web/sites/default
	vendor/bin/drush status # Validate new Drupal version
}

Why would all Bash function commands work besides a PHP Composer command?

What do you mean by "doesn't work"? Does it return with any specific error message? Did you also try without | grep 'latest'? Does the next composer update work fine though?

Side note - usually you first define a function, and then export it afterwards (not the other way round)

1 Like

By doesn't work I mean that I don't get any output associated with the first PHP Composer command -- not the correct output and not an exception, just nothing about it.

I must have | grep 'latest' there to know what is the latest version of Drupal before an actual upgrade is being done.

composer update works fine yes.

@droplet_lover,

try runnning ALL of the commands with debugging enabled
bash set -x
drush -d -v
(no idea if 'composer' has logging/debug functionality as I've never used it)
etc

put breakpoints/printf/prompt-for-continue/quit etc in the function to help ....

capture ALL the outputs to a log file , inspect and see if there's anything that might be relevant ...

come back with some actual content - not verbalisation ... ie it doesn't work (or variants thereof)

tks

A syntax example for one of these in the function would help.

After running set -x and drush -d -v and executing the function, the PHP Composer command output did show up.
I then ran set +x and executed the function again and the PHP Composer command output showed up again.

Either it appeared all along and I missed it or that drush -d -v caused it to appear.

@droplet_lover , ok, so have you resolved the issue or still investigating?

ps: the set -x need only be done inside the function.

2 Likes

I think the issue is resolved.

Thanks a lot.

1 Like