Shell脚本中拼接字符串诡异的从头替换的问题

这两天在部署脚本时总是会出现一个非常诡异的问题大致如下: #!/bin/bash # ab变量为环境变量,例如Hello result="hello${ab}${1}!" echo $result 执行./script.sh World,本来认为是

Hello World!

,结果确是

World!

这种莫名其妙的替换让我百思不得其解,翻了无数遍shell变量教程。终于鬼使神差发现是文件格式的问题。利用dos2unix命令后执行结果恢复。

作者

Carry

发布于

2024-10-21

更新于

2026-05-23

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.