Skip to content

Commit

Permalink
fix: publish string debug
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Oct 29, 2018
1 parent 6bd36d3 commit 669d147
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
9 changes: 9 additions & 0 deletions public/blog/_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4926,5 +4926,14 @@
"web"
],
"published": true
},
"shell-debugging-vanishing-text": {
"title": "Debugging vanishing text in shell scripts",
"date": "2018-10-29 08:23:25",
"modified": "2018-08-28 17:04:35",
"tags": [
"code"
],
"published": true
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Debugging vanishing text in shell scripts

Did you ever get a weird bash scripting issue where a variable would "randomly" eat characters of another command?
Did you ever get a weird bash scripting issue where a variable would "randomly" eat characters of another command?

No…? Well, I have, quite a few times, so I figured it was time I wrote up my fix.

Tools used: `curl`, `awk` and `od`

<!--more-->

## The issue
Expand All @@ -20,7 +22,7 @@ curl https://api.tinify.com/shrink -D /dev/stdout \
https://api.tinify.com/output/kdn3bvw6wzb2tqj869n6c5yq0tc34gt9
```

Note that I'm using `printf` in `awk` so that a `\n` isn't added.
Note that I'm using `printf` in `awk` so that a `\n` isn't added.

The second request would do this:

Expand Down Expand Up @@ -76,13 +78,15 @@ The final result:
```bash
function shrink() {
# first upload and compress the filename argument
local URL=$(curl https://api.tinify.com/shrink \
--user api:$TINIFY_KEY \
--dump-header /dev/stdout \
--data-binary @$1 | \
awk '/Location/ { gsub(/[[:space:]]+$/, ""); printf $2 }'
)
# then download and overwrite the file with the newly shrunk file
curl -X POST $URL --user api:$TINIFY_KEY --dump-header /dev/stdout --output $1 -H 'content-type: application/json' -d'{"resize":{"method":"scale","width":1320}}'
}
```
```
10 changes: 0 additions & 10 deletions public/drafts/_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,6 @@
"code"
]
},
"shell-debugging-vanishing-text": {
"title": "Debugging vanishing text in shell scripts",
"date": "2018-08-28 17:04:35",
"modified": "2018-08-28 17:04:35",
"complete": false,
"inprogress": true,
"tags": [
"code"
]
},
"gym-tech": {
"title": "Gym Tech",
"date": "2018-09-18 07:34:53",
Expand Down

0 comments on commit 669d147

Please sign in to comment.