I'm trying to write a function that takes n parameters and joins them into a string.
In Perl it would be
my $string = join(' ', @ARGV);
but in bash I don't know how to do it
function()
{
??
}
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
Bash makes it extremely easy to define functions with parameters. In this example, we will create the hello_world function and pass a string as an argument by its position using shell variables. That is $1 , $2 , and so forth. Copy #!/bin/bash hello_world () { echo "Hello $1" } hello_world "World Again!"
Check the bash
man page for the entry for '*' under Special Parameters.
join () {
echo "$*"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With