0

I am creating automatic plugin update function using bash and wp cli command.Using bash script i have checking update available plugins and storing those plugin names in a text file. Now i want to update plugin one by one by reading the plugin name from text file i created. When reading plugin name from text file i want to display "Do you want to update ? Y/N " command on terminal. If user submit yes then update first plugin else show "Do you want to update ? Y/N " command for second plugin.

I have written code for that but its not working. Its not displaying "Do you want to update ? Y/N " on terminal. I added that code inside the while loop of bash script.

How can i display "Do you want to update ? Y/N " on terminal by using while loop in bash script ??? Then i want to update plugin based on user input is equal to Y. if user input is N then dont update that plugin.

Following are my code its not working now.

read -p "Do you want to list Plugin updates for $user ? Y/N " -n 1 -r
  echo
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    echo
    # Display the list of plugins
    wp plugin list --update=available
    wp plugin list --update=available --field=name > plugins.txt
    while read p; do
    read -p "Do you want Plugin updates for $p ? Y/N " -n 1 -r
        if [[ $REPLY =~ ^[Yy]$ ]]
            then
            echo
            wp plugin update $p
        fi
        done <plugins.txt
  fi
  echo "-----------------------------------------------------------"
echo "Finished!"
Compo
  • 36,585
  • 5
  • 27
  • 39
developerme
  • 1,845
  • 2
  • 15
  • 34
  • 1
    This question has nothing to do with PHP nor Wordpress. Remove these tags from it. – adripanico Aug 29 '19 at 10:30
  • @adripanico thanks that was my mistake i removed that – developerme Aug 29 '19 at 10:31
  • @Inian How this will come under duplicate ? – developerme Aug 29 '19 at 10:37
  • See another duplicated - https://stackoverflow.com/questions/6883363/read-input-in-bash-inside-a-while-loop – Inian Aug 29 '19 at 10:39
  • But those are different answer, I want to read file first then need to display that question on terminal based on answer need to update plugin – developerme Aug 29 '19 at 10:41
  • Both question are different question then how it will come under duplicate ?? – developerme Aug 29 '19 at 10:43
  • Instead of seeking clarification here, you can spend time looking at the linked questions. Those have been provided for your understanding - look at this answer https://stackoverflow.com/a/9688579/5291015 and modify your logic similarly – Inian Aug 29 '19 at 10:46
  • `while read -u 9 p; do read -p "Do you want Plugin updates for $p ? Y/N " -n 1 -r if [[ $REPLY =~ ^[Yy]$ ]] then echo wp plugin update $p fi done 9 – Inian Aug 29 '19 at 10:48
  • Add a seperate file descriptor `9` for the outer while read loop of your plugins.txt file, so that it does not affect your inner read command – Inian Aug 29 '19 at 10:50
  • while read -u 9 p; do read -p "Do you want Plugin updates for $p ? Y/N " -n 1 -r if [[ $REPLY =~ ^[Yy]$ ]] then echo wp plugin update $p fi done 9 – developerme Aug 29 '19 at 11:25

0 Answers0