how can I join given arguments (not starting from the first one) to form one string, each argument separated by a space. For example, out of 5 given arguments, I'll like to start joining from the 3rd to the last. In python there exists something like ' '.join(sys.argv[3:]) and it starts joining from the 3rd argument to the last, each separated by a space. I looked for something similar to "join()" but couldn't find one, so I decided to write a script which joins the arguments.
My script looks like this:
#!/bin/bash
result=""
for (( i = 3 ; i <= $#; i++ ))
do
result=$result" \$$i"
done
echo $result
The only way I could think of was using evil eval:
#!/bin/bash
result=""
for (( i = 3 ; i <= $#; i++ ))
do
result=$result" "$( eval "echo \${$i}" )
done
echo $result
Be careful, because any errors inside the eval aren't caught at parse time, but show up during run time, which can lead to bad things when you don't expect them.