subdiox
subdiox

Reputation: 387

How to escape this code in Swift

This is a very simple question.
How can I escape this code in Swift?
find . -name "*.flv" -exec sh -c 'avconv -i "{}" -c copy "$(echo "{}" | sed s/\.[^.]*$/.mp4/g )"' \;

I tried to use \ to escape this, but it failed.

My Playground Screenshot: https://dl.dropboxusercontent.com/u/97497395/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202016-02-29%2017.03.51.png

Upvotes: 0

Views: 56

Answers (2)

subdiox
subdiox

Reputation: 387

Sorry, I solved by myself.
This is the solution:
let command:NSString = "find . -name \"*.flv\" -exec sh -c \'avconv -i \"{}\" -c copy \"$(echo \"{}\" | sed s/\\.[^.]*$/.mp4/g )\"' \\;"
Thank you for the help.

Upvotes: 0

sschale
sschale

Reputation: 5188

You need to escape each and every " by placing a \ in front of them. They are ending your string early.

Upvotes: 2

Related Questions