bash – 脚本中的`ln -s`充当`cp`
问题
我有这个bash脚本: ACTIVE_DB=$(grep -P "^[ t]*db.active" config.properties | cut -d= -f2 | tr -s " ") echo $ACTIVE_DB if [ "$ACTIVE_DB" = "A" ] then ln -sf config-b.properties config.properties else ln -sf config-a.properties config.properties fi config-a.properties db.active = A config-b.properties db.active = B 当我运行脚本时,执行硬拷贝(= cp)并且config.properties通常不是符号链接(也不是物理链接),而是一个与config-a.properties具有相同内容的全新文件或config-b.properties. $ls -li 53 -rw-r--r-- 1 ogregoir ogregoir 582 Sep 30 15:41 config-a.properties 54 -rw-r--r-- 1 ogregoir ogregoir 582 Sep 30 15:41 config-b.properties 56 -rw-r--r-- 1 ogregoir ogregoir 582 Oct 2 11:28 config.properties 当我在提示中逐行手动运行它时,我没有遇到麻烦,确实总是创建一个符号链接,并且config.properties指向config-a.properties或config-b.properties. $ls -li 53 -rw-r--r-- 1 ogregoir ogregoir 582 Sep 30 15:41 config-a.properties 54 -rw-r--r-- 1 ogregoir ogregoir 582 Sep 30 15:41 config-b.properties 55 lrwxrwxrwx 1 ogregoir ogregoir 20 Oct 2 11:41 config.properties -> config-b.properties 笔记 >其他任何地方都没有打开文件(我是唯一的活动用户,使用该配置的应用程序未运行). 题 >为什么我的脚本不能始终创建符号链接但是制作硬拷贝?
我怀疑你有一些其他的脚本或代码覆盖了符号链接.例如,sed -i将废弃符号链接.有许多命令和实用程序可以通过创建副本,修改副本,然后将副本移动到原始文件顶部来修改文件,从而破坏原始符号链接.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |