I've been setting up a script to work with haste-server. This takes piped or file input (tail /var/log/messages | haste
and haste < /path/to/file.txt
) and submits it to the server which then outputs a in my terminal. See below:
#!/bin/bash
url="http://hastebin.com"
key="$(curl --silent --data-binary @/dev/fd/0 $url/documents | cut -d "\"" -f 4)"
echo "$url/$key"
It works just fine, however it adds a trailing new line to the input. How can I read @/dev/fd/0
to remove the \n
new line?
Edit: Here is my completed script for submitting a haste that trims the newline:
#!/usr/bin/env bash
url="http://hastebin.com"
data=$(< /dev/fd/0)
key="$(printf "%s" "$data" | curl -X POST -s --data-binary @- "$url/documents" | cut -d "\\"" -f 4)"
echo "$url/$key"
a
? Where is the newline in that? You re adding a newline with theecho
command useecho -n
instead. – Anthon Feb 17 '15 at 09:52[ -t 1 ]
test for a terminal on stdout, andtput
can help with the escapes. If you're having difficulty with the eat the newline thing,printf '\033[@\n'
and have a look at how it behaves, – mikeserv Feb 18 '15 at 11:05