![]() Of course it works even for filenames with spaces in it.īTW: Every time you type something in Terminal you create a script, even if it is only a single command with one word like ls or date etc. So let's just feed the script produced by the one-liner script to sh, which is the script interpreter of OS X. ![]() ![]() You can create/modify not only output using commands, but also commands (right, that is commands created by a command, which is what Brian Kernighan, one of the inventors of Unix, liked most on Unix), so let's take a look what the ls and the sed produces by removing the pipe to sh: $ ls | sed 's/^\(.*\)\.txt$/mv "\1.txt" "\1.md"/'Īs you can see, it is not only an one-liner, but a complete script, which furthermore works by creating another script as output. Why looping with for if ls by design loops through the whole list of filenames? You've got pipes, use them. The preferred Unix way to do this (yes, OS X is based on Unix) is:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |