Hacker News new | past | comments | ask | show | jobs | submit login

Is this macro from the article dangerous because it doesn't quote the argument?

  Control-j: "\C-a$(\C-e)"
I can never remember how expansion and variable substitution work in shells.



The macro means:

  \C-a: beginning of line
  $: self-insert
  (: self-insert
  \C-e: end of line
  ): self-insert
So if your prompt (with | for cursor) looks like this:

  grep 'blah blah' |some_file
And you execute that macro, you get:

  $(grep 'blah blah' some_file)|
Which is correctly quoted and I think always correctly quotes whatever is at the prompt (unless you e.g. get half way through a string and press enter so the beginning of the prompt is halfway through a string, or maybe if you have multiple lines)


Yeah, but this and this do different things:

  # prints a newline
  echo $(echo "-e a\nb")

  # prints "-e a\nb"
  echo "$(echo "-e a\nb")"




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: