Search code examples
bashshellcygwin

passing folder path as argument from windows batch file to cygwin bash script


I am trying to execute the following command in a shell script :

find "$1" -type f -name "*.DAT" -exec sed -e 's/.*/\"&\"/' {} ';' -exec xargs wc -l ';'

the command is supposed to run from a windows batch file as follows:

set arg1=%1
C:\cygwin64\bin\bash.exe row_count.sh %arg1%

Where row_count.sh is the shell script containing the find command above. The user is supposed to pass in a folder path to the batch file which is then supposed to pass on the folder path parameter to the find command in the shell script.

But I am getting following error:

FIND: Invalid Switch

please help.


Solution

  • FIND: Invalid Switch is a error message from windows find not from cygwin one.

    So you need to use a login shell to properly set the PATH

    C:\cygwin64\bin\bash.exe -l row_count.sh %arg1%
    

    In addition be sure to put on the first row of row_count.sh the #!/bin/bash