Re: long string using find and "-exec ls -ls" to find part-of fi

看板FB_questions作者時間11年前 (2014/07/01 06:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串17/20 (看更多)
On Mon, 30 Jun 2014 14:55:34 -0700, Gary Kline wrote: > how about whitespace? ls -lsi appears as two cmds, so would > it work as you have with backtics? > > find ... | xargs -n 1 `ls -lsi` Erm... this looks wrong. Either find or ls, but both... except of course you want a ls -lsi output for each item found by find... :-) In case of whitespaces in filenames, you need to use at least "..." (double quotes), that's why using a variable here is probably the safer solution. Note that the whitespace has a special meaning to the shell: it's the standard field separator, separating commands and command line arguments. The output separator of ls and find is a newline, so the following should work for files with spaces: #!/bin/sh OLD_IFS=$IFS IFS=" " ls -lsi *.tar.gz *.tgz | while read F; do some_command "$F" done IFS=$OLD_IFS First, IFS is set to newline. Then ls with the desired options is run. Its results are separated by a newline. They are piped to the while read construct which reads one line = one result item at a time, executing the command. The double quotes make sure that each result (which can contain spaces) is provided as _one_ command line argument. Finally, IFS is restored. But the articles I mentioned before do cover this quite compli- cated topic much better. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
文章代碼(AID): #1JiULYF- (FB_questions)
討論串 (同標題文章)
完整討論串 (本文為第 17 之 20 篇):
文章代碼(AID): #1JiULYF- (FB_questions)