Conversation
tagatac
left a comment
There was a problem hiding this comment.
Any chance you could explain the reason for piping to read? What problem were you experiencing that it solves?
| )))" | cut -c 2- | awk -v home=$HOME '{print home $0}' | tr '\n' '\0' | xargs -0 -I fname cp fname $BACKUP_DIR/$contactNumber/Attachments | ||
| fi | ||
|
|
||
| done <(sql "SELECT DISTINCT guid FROM chat;" ) |
There was a problem hiding this comment.
| done <(sql "SELECT DISTINCT guid FROM chat;" ) | |
| done < <(sql "SELECT DISTINCT guid FROM chat;" ) |
Without input redirection, this file fails to parse. https://stackoverflow.com/a/26912746
| @@ -0,0 +1,59 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
| #!/bin/bash | |
| #!/usr/bin/env bash |
Don't limit it to the system bash. Mac OS bash is old:
❯❯❯ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
Copyright (C) 2007 Free Software Foundation, Inc.
| @@ -0,0 +1,59 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
No need to rename this file. .sh is a fine extension for bash scripts. The advantage of not renaming it is that GitHub will show us your changes inline.
| sqlite3 ~/Library/Messages/chat.db "$1" | ||
| } | ||
|
|
||
| for line in $(select_rows "select distinct guid from chat;" ); do |
There was a problem hiding this comment.
This is replaced by the read because this for relies on "word splitting" while the sqlite3 output is line-based. It's a disagreement between output and parsing that can lead to bugs. Using read, the input is parsed in a line-based manner. IFS is set empty to prevent read's default behaviour of trimming whitespace from the input. It's essentially an idiom, not necessarily tweaked specifically from a requirement of this specific sqlite3's output.
Changed the script to bash (macOS ships with bash), allows more safe syntax and improves the name pun!