2

I associated .sh files with bash. So I can successfully execute bash scripts from within a Windows command prompt.

The problem is that I am unable to pass command line arguments to my bash scripts from the Winodws command line.

The command line arguments are processed fine if I first go to bash and then execute the scripts their.

So if myscr.sh is

echo Args $1, $2

Then

c:\> myscr.sh a1 a2
Args ,

but from bash:

$ ./myscr.sh a1 a2
Args a1, a2

Any suggestions?

5
  • The outputs you have pasted seem inconsistent, bash should output "Args a1, a1" and not "Args a1, a2". Why not add echo of $# and check the value? Also maybe you could try bash myscr.sh a1 a2 on Windows and see what you get Commented Mar 15, 2012 at 7:44
  • Do you have a #!... line at the beginning of your script ? If yes, could you show us? Because it might no be bash which is running your script in fact, even when you call it from bash. (for example, if your 1st line is #!/usr/bin/python, then calling ./myscr.sh will invoke /usr/bin/python myscr.sh) (sample on Unix server, but same idea with Windows) Commented Mar 15, 2012 at 7:55
  • Thanks for the correction. bash myscr.sh also did not work, and the output of $# is '0'. Shebang is also included, just omitted for brevity Commented Mar 15, 2012 at 7:55
  • I'm having the exact same problem! However, the proposed solution did not work for me. Any other ideas? Commented Jan 25, 2015 at 21:23
  • I think solved it. Apparently, ftype association did not update the registry. Commented Jan 25, 2015 at 22:26

1 Answer 1

2

It turns out to be an association issue.

C:\> assoc .sh
.sh=sh_auto_file

C:\> ftype sh_auto_file
sh_auto_file="C:\cygwin\bin\bash.exe" "%1"

That was wrong. It did not pass the params to bash. To fix it, just add %* to the ftype

C:\> ftype sh_auto_file="C:\cygwin\bin\bash.exe" %1 %*

And all params will be passed.

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

Comments

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.