diff --git a/public/blog/_data.json b/public/blog/_data.json index a856af0f6..0f2d0b553 100644 --- a/public/blog/_data.json +++ b/public/blog/_data.json @@ -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 } } \ No newline at end of file diff --git a/public/drafts/shell-debugging-vanishing-text.md b/public/blog/shell-debugging-vanishing-text.md similarity index 93% rename from public/drafts/shell-debugging-vanishing-text.md rename to public/blog/shell-debugging-vanishing-text.md index 3c584f91e..b3cab7b21 100644 --- a/public/drafts/shell-debugging-vanishing-text.md +++ b/public/blog/shell-debugging-vanishing-text.md @@ -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` + ## The issue @@ -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: @@ -76,6 +78,7 @@ 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 \ @@ -83,6 +86,7 @@ function shrink() { 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}}' } -``` \ No newline at end of file +``` diff --git a/public/drafts/_data.json b/public/drafts/_data.json index 777e30f09..aaf81aca7 100644 --- a/public/drafts/_data.json +++ b/public/drafts/_data.json @@ -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",