bash - 如何在 bash 中对所有字符(特殊和非特殊)进行 url 编码
问题描述
如何对 bash 中的所有字符进行 url 编码?
例如:
abcd0123 => %61%62%63%64%30%31%32%33
我在 Linux 中尝试了内置的 urlencode 函数,但它只编码特殊字符,如 (.?)
解决方案
我不相信这在纯 Bash 中是可能的,但是可以将其他 shell 实用程序串在一起来实现这个结果,例如
urlencode() {
printf %s "$1" | od -An -tx1 -v -w${#1} | tr ' ' %
}
urlencode abcd0123 # => %61%62%63%64%30%31%32%33
推荐阅读
- swift - Swift NSNotification 观察者不工作
- python - 我正在尝试使用 MoviePy 模块将视频 mp4 文件转换为音频 mp3 格式,但它向我显示 Nonetype 错误
- prometheus - 将从 AWS Fargate Task 公开的自定义应用程序指标集成到 prometheus
- python - Django 纯文本电子邮件模板在模板标签后生成\n
- stata - 如何在Stata中声明“字符串”条件?
- java - 在“导入 Maven 项目”和“构建 Maven 项目”期间发生内部错误
- c++ - 有什么方法可以在 c++ 中通过更大的 int 和更小的对对 int 和pair 进行排序?
- javascript - Jest 中如何执行异步测试
- sql-server - SQL Server 2016,在 SQL Server 表中检查用户登录和散列密码的功能出现问题
- quarkus - 如何将整个日志发送到 Quarkus 中的 jeager span?