理解代码({0..1} {0..1} {0..1} {0..1} {0..1} {0..1} {0..1} {0..1 }) [英] Understanding code ({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})

查看:105
本文介绍了理解代码({0..1} {0..1} {0..1} {0..1} {0..1} {0..1} {0..1} {0..1 })的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Bash shell十进制到二进制转换中看到了以下代码我想知道它是如何工作的?我尝试谷歌搜索无济于事.

I saw the following code in Bash shell Decimal to Binary conversion and I was wondering how it works? I tried googling with no avail.

D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})

echo ${D2B[7]}

上面的代码有什么作用?

What does the code above do?

推荐答案

{N..M},对于整数文字N和M,生成从N到M的整数序列,包括整数(包括空格).这称为"括号扩展",并且是

{N..M}, for integer literals N and M, generates the series of integers from N to M, inclusively, separated by spaces. This is called a "brace expansion", and is a bashism. As you can see, all brace expansions are done before adding spaces between them.

variable=({some expansion})将每个展开的项目放在数组${variable[index number]}提取该索引处的值.因此,您的代码有效地以二进制字符串形式返回了数字7.

variable=({some expansion}) puts each of the expanded items in an array, and ${variable[index number]} extracts the value at that index. So your code effectively returns the number seven in binary string form.

这篇关于理解代码({0..1} {0..1} {0..1} {0..1} {0..1} {0..1} {0..1} {0..1 })的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆