kareman / SwiftShell

A Swift framework for shell scripting.
https://kareman.github.io/SwiftShell
MIT License
1.03k stars 87 forks source link

How to execute rm -rf /xxx/* #102

Closed cdwmhcc closed 3 years ago

cdwmhcc commented 3 years ago

run("rm", "-rf", "/xxx/swift shell/a.txt") is working, But run("rm", "-rf", "/xxx/swift shell/*") it does not work

what should I do?

kareman commented 3 years ago

In order to use * you must use bash, like this: run(bash: "rm -rf /xxx/swift\ shell/*"). Be careful with that command though, it deletes everything in that folder.

cdwmhcc commented 3 years ago

In order to use * you must use bash, like this: run(bash: "rm -rf /xxx/swift\ shell/*"). Be careful with that command though, it deletes everything in that folder.

Thanks for your help.

I tried it and it didn't work. I now use a for loop to generate relative paths and it works.

cdwmhcc commented 3 years ago

Use: If there are spaces in the path, use single quotes to wrap the constant let all:Bool = true runAsync(bash: "rm '\(path)'\(all ? "/*" : "")")

is working