I'm trying to execute a mono application, without requiring the user to type in 'mono filename'. It's just one line of code:

mono ./Bin/jobshop.exe $1 $2 $3 $4 $5 $6 $7 $8 $9

It works great, so long as I call it from the correct directory. But if my current directory isn't exactly where the script is - it fails because the ./Bin is relative to the current directory. I want it to be relative to the location of the script.

I found that I was able to get the location of the script using

echo dirname "$(readlink -f "$0")"/Bin/jobshop.exe $1 $2 $3 $4 $5 $6 $7 $8 $9

That displays correctly on the screen; but I can't figure out how to put it into my first script such that mono executes that value.

I'm using 'tcsh', however I would prefer an answer agnostic to any shell.

I just want to run 'mono' + 'dirname "$(readlink -f "$0")"/Bin/jobshop.exe $1 $2 $3 $4 $5 $6 $7 $8 $9'

But I can't seem to get it right.


Try this:


path=$(dirname $(readlink -e -- "$0"))

/path/to/mono "$path"/Bin/jobshop.exe "$@"
  • You should save your program path in $path variable.
  • Use "$@" instead of listing all command line arguments.
| improve this answer | |

You could say:

mono $(dirname "$(readlink -f "$0")")/Bin/jobshop.exe $1 $2 $3 $4 $5 $6 $7 $8 $9
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.