Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to generate a local array in a shell/bash script that consists of the following elements: JF-1998, JF-1999, JF-2000,... , JF-2011. That is, a string JF- combined with the years from 1998 to 2000.

I would also like to be able to do the reverse: Combine a number with a limited number of strings before that number: JF-1998, RFS-1998, JFI-1998.

Are there simple ways to do so?

share|improve this question
5  
You mean something like arr=( JF-{1998..2011} )? –  steeldriver Dec 28 '14 at 0:14
    
@steeldriver: I added a new part to the question because I didn't want to cast a new one. Do you also know how to deal with combining some strings with a fixed number? –  MERose Dec 28 '14 at 22:33
    
@MERose The converse of that usage: {JF,RFS,JFI}-1998 –  muru Dec 28 '14 at 22:59
    
@steeldriver Can I put JF,RFS,JFI in a variable? For me it didn't work when in do names=(JF,RFS,JFI) and then {$names}-1998. Also no spaces instead of commas. –  MERose Dec 28 '14 at 23:55
    
This type of variable expansion is known as brace expansion because you need braces: for example echo {JF,RFS,JFI}-1998 –  steeldriver Dec 29 '14 at 0:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.