Skip to main content

Timeline for Escape characters from echo -e

Current License: CC BY-SA 3.0

9 events
when toggle format what by license comment
May 23, 2017 at 12:39 history edited CommunityBot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Dec 1, 2015 at 12:26 comment added type_outcast For example, with some work to log itself, you could use here documents, which would mean log <<EOF<Enter>here's my entry<Enter>EOF<Enter> It's more typing than simply escaping, though. Similarly, you could use stdin like log<Enter>here's my entry<Enter><Ctrl-D> Again, more typing. You could make log interactive, so you type a line and hit <Enter>, but it stays running so you can just leave it go in a separate terminal. You could find or write your own custom shell that has simpler escaping. Many options.
Dec 1, 2015 at 12:14 comment added type_outcast OK, fair enough. Assuming you're logging one message at a time (with other commands in between your log entries), there isn't a whole lot more you can do. For casual things like this, I've personally just gotten used to using quotes and escaping, depending on the specific text in each message. E.g., I'd use log Plain old string vs. log "Don't look" vs. log 'This "job" is too much fun' vs log I could sure use \$20. Unfortunately, if that bit of extra typing is unacceptable for you, then you would need to modify your requirement of being able to type the messages at a bash shell prompt.
Dec 1, 2015 at 11:58 comment added Proletariat Basically, from the terminal, log the stuff isn't working. Then it will input the text after log into a text file with date and timestamp.
Dec 1, 2015 at 11:51 comment added type_outcast You can use double quotes, as in log "it's my life", but that runs into similar problems if you'll ever have double quotes in your string (or any other characters that need to be escaped (see the question I linked in my answer). This is a problem with shell commands in general. You can use input redirection or here documents, but then you no longer have a one-line command. Can you tell me more about how your log command will be used?
Dec 1, 2015 at 10:03 comment added Proletariat Is there a way to achieve the functionality of my log script without having to escape any characters?
Dec 1, 2015 at 10:00 vote accept Proletariat
Nov 30, 2015 at 15:42 history edited type_outcast CC BY-SA 3.0
Explained why unmatched single apostrophes result in the extra prompt lines the OP sees
Nov 30, 2015 at 15:35 history answered type_outcast CC BY-SA 3.0