~drscream

bash, sequences of numbers or characters

In bash there is an easy way to generate a sequence of numbers or characters. By defining a start and stop character with the ‘..’ in between:

$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z

The example above works with lower and upper case characters. Use upper and lower case characters in mix:

$ echo {A..z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [  ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z

It also work with numbers:

$ echo {0..9}
0 1 2 3 4 5 6 7 8 9
$ echo {0..22}
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Another way to generate a list of numbers is using the command line tool seq:

$ seq 1 4
1
2
3
4

To change the delimiter you can use the parameter -s “delimiter”, for example with a space:

$ seq -s " " 1 10
1 2 3 4 5 6 7 8 9 10

Send your comment by mail.