This question is more oriented on what is the best practice to treat arguments in bash functions. Let's take a look to the following code:
#!/bin/bash
do_something () {
echo "$1"
}
do_something_1 () {
echo "$1"
}
do_something_2 () {
echo "$1"
}
do_something_3 () {
echo "$1"
}
echo "$1"
do_something
do_something "hi"
do_something_2 "hello"
do_something_3 "bye"
And let's imagine I am calling the script:
./myscript.sh param1
This will output:
param1 #First parameter passed to the string
#Nothing, as I am passing nothing to do_something
hi #first parameter of do_something
hello #first parameter of do_something_2
bye #first parameter of do_something_3
but if I take a look at the functions, all of those are called "$1". Now, I understand this, but this doesn't seems readable. What if the code is bigger? I will need to go to the caller of the function to see what argument was passed (and ignore the parameter that was passed to the script), and it will become more and more difficult to know/maintain what is inside the parameters passed.