Reputation:
I am writing a shell script from a book, and there is an example where I am creating a function and invoking that function later with $(function_name)
.
But as far as I know, I can invoke a function by just writing its name.
So, what is the difference between calling a function with its name and with $(function_name)
?
Upvotes: 1
Views: 1338
Reputation: 195209
$(...)
is called command substitution.
Simply put, function_name
will print the output, done.
$(function_name)
the output from the function will become a part (usually as an argument) as a new command to be executed.
echo "ls" #<--- assume this is the function
Open a terminal, and give this a try, you will understand it better:
echo "ls"
and
$(echo "ls")
Upvotes: 2