bash 获取文件中字符串_如何在Bash的ASCII表中获取一个字符的下一个字符?

bash 获取文件中字符串

How to get the one character’s next character in ASCII table in Bash? For example, if I have ‘a’ in variable i, how to get ‘b’?

如何在Bash的ASCII表中获取一个字符的下一个字符? 例如,如果我在变量i有“ a”,如何获得“ b”?

First, we need to get the integer value for the character.

首先,我们需要获取字符的整数值。

char='b'
charint=$(printf "%d" "'$char'")

Then, we increase the integer by one

然后,我们将整数增加一

let charint=$charint+1

Last, we can get the new character by converting the integer to the character

最后,我们可以通过将整数转换为字符来获得新字符

newchar=$(printf "\x$(printf %x $charint)")

Here, we use the inner printf to convert the integer to hexadecimal value and the outer printf to print the character from its hexadecimal value.

在这里,我们使用内部printf 整数转换为十六进制值,并使用外部printf从字符的十六进制值打印字符。

The result is as follows.

结果如下。

$ echo $newchar
c

翻译自: https://www.systutorials.com/how-to-get-the-one-characters-next-character-in-ascii-table-in-bash/

bash 获取文件中字符串

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值