How to generate letter sequence list in fish shell

风流意气都作罢 提交于 2020-01-11 11:09:33

问题


In bash you can generate letter sequence easily as "{a..z}", for example

$ 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

How to do that in the fish shell instead?


回答1:


Fish doesn't support ranges in brace expansion, only comma-separated values: {a,b,c}.

Thus, we are forced to search for a command capable of generating such sequence. For example, you can use Perl:

for c in (perl -e '$,="\n"; print ("a" .. "z")')
  printf ">> %s\n" "$c"
end

where $, is the output field separator.

Output

>> a
>> b
...(skipped)
>> y
>> z

You may find this table useful.




回答2:


One way is to use printf and seq.

echo -e (printf '\\\x%x\n' (seq 97 122))

This works by generating "\x61 \x62 \x63 ... \x7a" which is then interpreted by "echo -e" as hex character codes.




回答3:


Linux has the seq command for this, and it works with fishshell:

$ for f in (seq 1 10)
    echo $f
end
1
2
3
4
5
6
7
8
9
10
$


来源:https://stackoverflow.com/questions/40943953/how-to-generate-letter-sequence-list-in-fish-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!