Bash (Scripting) - Replace value in a list
                
            
            
            
             
            
            
                           
                
            
            
            
                
    
    
     
            
                
                    by
                    Jeremy Canfield  |  
                    Updated: November 10 2023
                    
                          |  Bash (Scripting) articles
                    
                    
                    
                
            
            Let's say you have the following.
#!/bin/bash
fruit=(apple banana orange grapes)
echo ${fruit[*]} 
Running this script should return the following.
apple banana orange grapes
Here is how you can replace a value in the list.
#!/bin/bash
fruit=(apple banana orange grapes)
fruit=("${fruit[@]/orange/peach}")
echo ${fruit[*]} 
Which should now return the following.
apple banana peach grapes
Did you find this article helpful?
If so, consider buying me a coffee over at 