I'm creating a bash script to check if a symlink target matches a specific path so, in case it doesn't match, script removes the symlink. I've tried with 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
but it doesn't work:
%source test test:5: = not found
Showing soft link using Find command in Unix When you use the find command with option type and specify the type as small L ( l for the link), it displays all soft links in the specified path.
In order to follow symbolic links, you must specify ls -L or provide a trailing slash. For example, ls -L /etc and ls /etc/ both display the files in the directory that the /etc symbolic link points to. Other shell commands that have differences due to symbolic links are du, find, pax, rm and tar.
You should use double quotes as follow when you compare strings (and yes, the output of readlink $HOME/.slate.js
is a string):
[ "$(readlink $HOME/.slate.js)" = "$target_path" ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With