Search code examples
bashawksedcygwincygpath

How to get cygpath to take input from file


I apologize in advance for this question, but I am really stuck right now, and I'm just praying that someone out there can help me.

I have a series of c files I need to inspect one at a time in about 100 subdirectories, each named balance.d, balanced.c, or balancer.c. I've gotten a list of them using find . -name "balance*", and I can choose one of those using sed -n [NUM]p. This is a Windows environment using Cygwin, and these directories are all shared via Dropbox with other people. The paths often involve spaces, and I am running into trouble.

I know that cygpath -sw will give me paths without spaces. My eventual goal is to be able to grab each file, one at a time with gcc path/to/file.c -o ./a.exe

Right now, I've got

cygpath -sw $(echo find . -name "balance*" | sed -n 2p | awk '{gsub(/ /,"\ ")}8')

... but cygpath won't get my past the spaces. It gives me an error

awk: cmd. line:1: warning: escape sequence `\ ' treated as plain ` '


Solution

  • Put quotes around your command substitution or the result from it will undergo work splitting.

    Also what you are doing with AWK part is not needed.

    You are calling the echo command with the following arguments:

    [find] [.] [-name] [balance*]
    

    What you want it to call the find command:

    cygpath -sw "$(find . -name "balance*" | sed -n 2p)"