#!/bin/bash file='Config/Config.php' old_version='1.1.0' new_version='1.1.1' #替换配置文件版本 sed -i "s/$old_version/$new_version/g" "$file" exit 0
在linux执行正常,但在mac环境下执行出现以下错误:
$ cat ./Config/Config.php
// 版本
define('VERSION', 1.1.0);
$ ./update_config.sh
sed: 1: "Config/Config.php": invalid command code C
-i extension Edit files in-place, saving backups with the specified extension. If a zero-length extension is given, no backup will be saved. It is not recommended to give a zero-length extension when in-place editing files, as you risk corruption or partial content in situations where disk space is exhausted, etc.
sed -i "_bak" "s/a/b/g" "example.txt"
#!/bin/bash file='Config/Config.php' old_version='1.1.0' new_version='1.1.1' #替换配置文件版本 sed -i "_bak" "s/$old_version/$new_version/g" "$file" exit 0
$ cat ./Config/Config.php
// 版本
define('VERSION', 1.1.0);
$ ./update_config.sh
$ cat ./Config/Config.php
// 版本
define('VERSION', 1.1.1);
$ cat ./Config/Config.php_bak
// 版本
define('VERSION', 1.1.0);
#!/bin/bash
file='Config/Config.php'
old_version='1.1.0'
new_version='1.1.1'
#替换配置文件版本
sed -i "" "s/$old_version/$new_version/g" "$file"
exit 0
执行结果
$ cat ./Config/Config.php
// 版本
define('VERSION', 1.1.0);
$ ./update_config.sh
$ cat ./Config/Config.php
// 版本
define('VERSION', 1.1.1);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有