Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dash equivalent to bash's curly bracket syntax?

Tags:

dash-shell

In bash, php/{composer,sismo} expands to php/composer php/sismo. Is there any way to do this with /bin/sh (which I believe is dash), the system shell ? I'm writing git hooks and would like to stay away from bash as long as I can.

like image 382
greg0ire Avatar asked Jul 23 '13 09:07

greg0ire


2 Answers

You can use printf.

% printf 'str1%s\t' 'str2' 'str3' 'str4'
str1str2    str1str3    str1str4
like image 74
mikeserv Avatar answered Oct 02 '22 04:10

mikeserv


There doesn't seem to be a way. You will have to use loops to generate these names, perhaps in a function. Or use variables to substitute common parts, maybe with "set -u" to prevent typos.

I see that you prefer dash for performance reasons, however you don't seem to provide any numbers to substantiate your decision. I'd suggest you measure actual performance difference and reevaluate. You might be falling for premature optimization, as well. Consider how much implementation and debugging time you'll save by using Bash vs. possible performance drop.

like image 21
spbnick Avatar answered Oct 02 '22 04:10

spbnick