Bootstrap FreeKB - Bash (Scripting) - Replace value in a list
Bash (Scripting) - Replace value in a list

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 463dc5 in the box below so that we can be sure you are a human.