Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using bash wildcards with prefix

I am trying to write a bash script that takes a variable number of file names as arguments. The script is processing those files and creating a temporary file for each of those files.

To access the arguments in a loop I am using

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

After the loop is done, I want to do something like cat t_$* . But it's not working. So, if the arguments are a b c, it is catting t_a, b and c. I want to cat the files t_a, t_b and t_c.

Is there anyway to do this without having to save the list of names in another variable?

like image 337
Rakib Avatar asked Oct 28 '25 06:10

Rakib


1 Answers

You can use the Parameter expansion:

cat "${@/#/t_}"

/ means substitute, # means at the beginning.

like image 176
choroba Avatar answered Oct 29 '25 22:10

choroba