Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
added 90 characters in body
Source Link
Proletariat
  • 707
  • 3
  • 18
  • 29

I have the following in my .bashrc file I use for a log:

function log(){

  RED="\e[0;31m"
  RESET="\e[0m"
  echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt
}

But when I do something with an apostrophe in it, it comes up with some sort of prompt and does not log it properly.

How do I escape all the text being input into the file?

Example:

$ log this is a testing's post
> hello
> 
> ^C
$

Thanks.

I have the following in my .bashrc file I use for a log:

function log(){

  RED="\e[0;31m"
  RESET="\e[0m"
  echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt
}

But when I do something with an apostrophe in it, it comes up with some sort of prompt and does not log it properly.

How do I escape all the text being input into the file?

Thanks.

I have the following in my .bashrc file I use for a log:

function log(){

  RED="\e[0;31m"
  RESET="\e[0m"
  echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt
}

But when I do something with an apostrophe in it, it comes up with some sort of prompt and does not log it properly.

How do I escape all the text being input into the file?

Example:

$ log this is a testing's post
> hello
> 
> ^C
$

Thanks.

Source Link
Proletariat
  • 707
  • 3
  • 18
  • 29

Escape characters from echo -e

I have the following in my .bashrc file I use for a log:

function log(){

  RED="\e[0;31m"
  RESET="\e[0m"
  echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt
}

But when I do something with an apostrophe in it, it comes up with some sort of prompt and does not log it properly.

How do I escape all the text being input into the file?

Thanks.