-1

In windows if you create a shortcut to a .exe file or .bat, that file will run on its own directory, not where shortcut is, but in Linux, links pointing to scripts run in same directory as where link is and that breaks everything if said script is relies on files on its root directory, is there a way to solve it without shell wrappers or using absolute path?

I tried both hard links and soft links but they yield the same result.

3
  • It's the job of the script writer to account for this. Usually the first task in the script is to determine the "root directory" and cd there. A similar question: unix.stackexchange.com/q/17499/4667 Commented Jul 24, 2023 at 17:11
  • 2
    A shortcut is nothing like a hard or soft link. Links are a feature of the filesystem and appear identical to the files they link to. Shortcuts are only understood by explorer.exe and have no relationship to the file system. In Linux, I would write a simple script to do whatever I want as @glennjackman suggests. It is also possible that you could alias your problem away but you don't tell us what it is so I don't know. Commented Jul 24, 2023 at 18:37
  • You should re-word the question as its not clear what you are expecting. As noted by @LjmDullaart a link on Linux runs in the current directory, and your observations about Windows also appear incorrect. A Windows shortcut has a "Start In" directory which defines the current directory used for the target, and if no "Start In" is set the target is launched using the directory of the shortcut and not the target.
    – DuncG
    Commented Jul 26, 2023 at 13:17

2 Answers 2

1

Your observations are wrong. I cannot tel much about Windows, but on linux,

links pointing to scripts run in same directory as where link is

is not true. A link pointing to an executable runs in the directory where the program is started. You can easily verify this with

ln -s /usr/bin/ls /tmp/ls
/tmp/ls

This will output the contents of your current directory and not the contents of /tmp

It is unclear what you mean by 'it breaks everything'. Furthermore, you should avoid placing files in / unless it is absolutely necessary.

0

I have a softlink /ImageStore to a folder on a mounted Data-disk...

This:
$ linkpos="$(find /ImageStore -maxdepth 1 -printf "%l\n")"; ( cd $linkpos ; ls -l)

... will list the content of that folder.

In a similar manner you may extract a script path from "$linkpos", cd to that path and then execute the script.

The info you need on top of the above is in man bash, type /Parameter Exp and press ENTER as you're viewing the man page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .