1

I wrote a .net core command line app and I wanted to easily be able to run it from the command line on multiple platforms. For Windows I wrote a cmd file. For Linux and MacOs I wrote a bash script.

.net core apps compile to a DLL. To run them from the command line you enter:

dotnet myApp.dll <my command line args>

My bash script looks like:

#!/bin/sh
dotnet ./myApp.dll "$@"
rc=$?
exit $rc

When I run my app through the shell script I get the following error: ' is not recognized. But if I skip the shell script, and run the app directly as dotnet myapp.dll I get no error whether running on Windows or Linux.

I believe the error is being generated by the library I'm using for command line parsing, but I suspect the problem may be in my bash script. This is the library that I'm using for Command line parsing. https://github.com/commandlineparser/commandline

If I add echo "$@" to the top of the script, I see my command line argument echoed to the console.

Is there an error in my bash script? Is there a better way to write this script?

There could be multiple command line arguments and I want to pass them all to my application as if I had run the app directly using the dotnet cli.

3
  • 2
    Just a wild guess: Try changing your script file to unix line endings. Commented Jul 24, 2019 at 20:30
  • holy crap, I think that fixed it. Commented Jul 24, 2019 at 20:39
  • if you put that as an answer, I'll mark it correct. Commented Jul 24, 2019 at 20:41

1 Answer 1

3

Try changing your script file to unix line endings \n.

Sign up to request clarification or add additional context in comments.

1 Comment

for anyone who comes along later you can either use Notepad++ to do the conversion (Edit->EOL Conversion) or on Linux use dos2unix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.