-1

I am trying to write a script that will pull any photos or videos I've taken today. Here is what the code looks like:

for i in $(adb shell ls -l /sdcard/DCIM/Camera/ | grep $(date +%Y-%m-%d) | awk '{ print $7 }' ) ; do adb pull /sdcard/DCIM/Camera/$i ~/Photos ; done

And here is the error I get when I run it:

' does not existsdcard/DCIM/Camera/IMG_20160507_012827.jpg

It properly grabs the name the file(s) that need to be pulled, but for some reason it doesn't pass that information to "adb pull" properly.

Do I need to do something else to "sanitize" the output of one command into the input of the other?

  • Hi, the keyword "sanitize" took me here. Regarding the headline "adb shell one-liner not passing output properly", this seems to be a **valid question** that seems, however, not really to be a duplicate, like its closure claims reason. Steps to repsoduce: stuff `adb`'s output into a bash variable (`OUT=$(adb gimme sth); echo $OUT`), and see it crumbled in parts. That's the whole point here, which seems also missed by @monk's answer. – klaus Apr 24 '20 at 16:57
  • 1
    …while not being able to file a proper answer, I'll dump it here: • some `adb` commands (or at least `adb shell`) end their output lines with 0x0d and 0x0a, and that's what is confusing us right here. • sanitation is being done when you hand over the string to `tr`: `adb shell ls | tr -d '\r'` • you can inspect the output passing it to octal dump (`od`): `adb shell ls | od -c`, which tells you more about included special chars • this solution benefits largely from this answer: https://stackoverflow.com/a/802439/211514 – klaus Apr 24 '20 at 17:54

1 Answers1

-1

why don't you just try find to list down all the files which are modified in last 24 hours and copy them to desired directory ?

find ~/desired/source -mtime -1 -type f -print0 | xargs -0 cp -t ~/destination/picture
monk
  • 1,953
  • 3
  • 21
  • 41