Using bash wildcards with prefix

I am trying to write a bash script that takes a variable number of filenames as arguments. The script processes these files and creates a temporary file for each of these files.

To access the arguments in a loop I use

for filename in $*
do
   ...
   generate t_$(filename)
done

      

After the loop finishes, I want to do something like cat t_$*

. But it doesn't work. So, if there are arguments a b c

, it indicates t_a, b and c

. I want to cat files t_a, t_b and t_c

.

Is there a way to do this without storing the list of names in another variable?

+3


source to share


1 answer


You can use parameter expansion:

cat "${@/#/t_}"

      



/

means replacement, #

means at the beginning.

+8


source







All Articles