本文介绍了我将如何在bash中使该PHP行等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是PHP行:

intval(substr($strIn,$i, 2), 32);

我正在尝试将其转换为bash,首先我知道因为bash处理变量的方式不需要 intval ,所以我不需要第一部分,但是我已经阅读了有关 substr ,但是在这种情况下我不知道它的作用.有人知道bash相当于什么吗?

I'm trying to convert this to bash, first I know that intval is not needed because of how bash handles variables, so I don't need the first part, however I have read about substr, but I can't figure out what it does in this case. Does anyone know what the equivalent in bash would be?

推荐答案

substr($ strIn,$ i,2) $ strIn 返回2个字符,从偏移量 $ i 开始.例如, substr('foobar',3,2)返回'ba'.

substr($strIn, $i, 2) returns 2 characters from $strIn, starting with offset $i. For example, substr('foobar', 3, 2) returns 'ba'.

bash中的等效项是:

The equivalent in bash is:

STR=foobar
echo ${STR:3:2}

如果起始偏移量不是固定的,但存储在变量中,则如下所示:

If the start offset is not fixed but it is stored in a variable then it's just like this:

STR=foobar
i=2
echo ${STR:$i:2}          # It displays: ob

这篇关于我将如何在bash中使该PHP行等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 09:32