I have this simple script to use with seventh sense (it's a lone wolf gamebook reader/player):#!/bin/bashGAME_PATH=$(dirname $(readlink -f $0))SEVENTH_SENSE_PATH=$(echo ~)/.wine/drive_c/users/$(whoami)/Documentsmkdir -p $SEVENTH_SENSE_PATHln -s -f $GAME_PATH/Lone Wolf/books $SEVENTH_SENSE_PATH/Seventh Sensecd $GAME_PATH/Lone Wolfwine Lone\ Wolf.exeIt's very simple, only moving a directory inside the folder to the location that this windows program expects it on the wine dir - but that is not the problem.ln here works the first time (it creates a symlink to books named Seventh Sense inside the Documents folder of the wine user. The problem is, the second time it makes a books symlink inside the folder that the Seventh Sense symlink points to (ironically, exactly the original books folder), when run twice.It causes no harm, but it seems like an obvious bug that is escaping me.(books is a folder (inside the Lone Wolf folder that is at the same level as the script)).
ln gives different results when run multiple times
shell;utilities;symlink
ln, like cp and mv, behaves differently depending on whether the destination is an existing directory (including a symbolic link to one). If it isn't, then the source is copied/moved/linked to the desintation name. If the destination is an existing directory, the source is copied/moved/linked to a file of the same base name as the source, under the destination directory.With GNU ln (as found under Linux), use the -n option to overwrite the destination rather than writing under it when the destination is a symbolic link to a directory.ln -snf $GAME_PATH/Lone Wolf/books $SEVENTH_SENSE_PATH/Seventh SenseAlternatively, you can test if the destination is a directory, and not recreate it if exists.[ -d $SEVENTH_SENSE_PATH/Seventh Sense/. ] ||ln -s $GAME_PATH/Lone Wolf/books $SEVENTH_SENSE_PATH/Seventh SenseAlternatively, you can remove the target first and create it unconditionally.rm -f $SEVENTH_SENSE_PATH/Seventh Senseln -s $GAME_PATH/Lone Wolf/books $SEVENTH_SENSE_PATH/Seventh Sense