I’m working on a shell script and I have some lines of code that are duplicated (copy pasted, let’s say).
I want those lines to be in a function. What is the proper syntax to use?
And what changes shoud I do in order for those functions to receive parameters?
Here goes an example.
I need to turn this:
amount=1
echo "The value is $amount"
amount=2
echo "The value is $amount"
Into something like this:
function display_value($amount) {
echo "The value is $amount"
}
amount=1
display_value($amount)
amount=2
display_value($amount)
It is just an example, but I think it’s clear enough.
Thanks in advance.
1 Answer