0

I'm a new Ubuntu user. I am reading this book "The Linux Command Line: A Complete Introduction" and practicing the code. That's fun, but I have trouble in Chapter 8:

➜  ~ echo {1..10}
1 2 3 4 5 6 7 8 9 10
➜  ~ echo {z..a}
{z..a}
➜  ~ echo {Z..A}
{Z..A}
➜  ~ echo {a..z}
{a..z}
➜  ~ 

I can't get a range of letters. Why? How do I fix it? My shell is oh-my-zsh.

muru
  • 69,900
  • 13
  • 192
  • 292
Scott Ming
  • 1
  • 1
  • 2

1 Answers1

2

This is a ksh (and bash) feature and may not be in your shell, e.g., dash (default shell used in Debian/Ubuntu).

To see the difference, try

bash -c "echo {a..z}"
dash -c "echo {a..z}"

The default /bin/sh with Debian points to dash. But if you happen to be running in a bash shell, you will see the sequences expanded as you expect. Scripts beginning #!/bin/sh will use dash.

On my Debian 7, zsh also does not expand the sequence. (I checked ksh, bash, dash and zsh).

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • dash is `/bin/sh` on Debian and kids, but not the default shell for users - that is still bash. (And OP saying oh-my-zsh indicates their shell is zsh) – muru Feb 15 '16 at 01:06
  • ``` ➜ ~ bash -c "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 ➜ ~ dash -c "echo {a..z}" {a..z} ``` – Scott Ming Feb 15 '16 at 01:06
  • 1
    I checked bash, and it works, Thank you very much. I love Linux. – Scott Ming Feb 15 '16 at 01:22
  • For the record, `{1..10}` originates in `zsh` (also supporting `{00..03}`), `zsh` had `{a-z}` (with the `braceccl` option), not `{a..z}`. `ksh` later borrowed it and extended it with `{first..last[..incr][%fmt]}` and allowing some character ranges. `bash` copied a subset of ksh with some limitations/bugs. Eventually, `zsh` got the `{x..y..incr}` and character ranges (supporting any range). So, here the problem is that the OP is using too old a version of zsh. – Stéphane Chazelas Feb 15 '16 at 14:27