我正在创建一个bash脚本,以检查符号链接目标是否与特定路径匹配,以防其不匹配,脚本将删除符号链接。我试过readlink:
#!/bin/env bash target_path=$HOME/Code/slate/.slate.js if [ `readlink $HOME/.slate.js` == "$target_path" ]; then rm -rf "$HOME/.slate.js" fi
但它不工作:
%source test test:5: = not found
当您比较字符串时,应该使用双引号(和是,readlink $ HOME / .slate.js的输出是一个字符串):
原文链接:/bash/387430.html[ "$(readlink $HOME/.slate.js)" = "$target_path" ]