I use Gedit and enabled the Gedit Snippets plugin. I added a custom snippet for the sh language that shall contain a Bash variable like $LINENO. It looks like this simplified example:

my_command || ( echo "Error on line $LINENO" ; exit 1 )

However, if I let the plugin insert this snippet above, it tries to evaluate the $LINENO itself and removes it from the inserted code, so that I only get this result:

my_command || ( echo "Error on line " ; exit 1 )

Is there a way to make Gedit Snippets simply insert $LINENO literally, instead of trying to evaluate it?

  • 1
    Can you please give us a short example (only a few lines) that shows what you want to achieve? I'm having troubles to understand you... – Byte Commander Jun 26 '16 at 16:59
  • After editing a file, I use an or statement to catch if it failed and call my exit function, give the line number of the script, and a short explanation, like this: || error_exit "$LINENO: File edit failed." – Kevin Ruffus Jun 26 '16 at 19:56
  • I want the actual variable '$LINENO' to populate in the script I'm editing, but gedit tries to get the value and inserts a blank space, like this: || error_exit " : File edit failed.". The idea is that bash should be interpreting the variables value when the script is run, not gedit. Having to cut and paste that variable every time I use the error snippet I made is getting very frustrating. – Kevin Ruffus Jun 26 '16 at 19:59
  • did you try quotes or backticks around the variable? I assume you are talking about shell placeholders? – Rinzwind Jun 26 '16 at 20:07
  • 1
    I edited your question and removed all the long story around it and added a simple example. I hope everything I changed still fits your needs? – Byte Commander Jun 26 '16 at 20:23

You must simply edit your snippet and escape the $ in Gedit's snippet manager with a \ backslash, just as you can see in the screenshot below.

That way the $LINENO will not be evaluated by Gedit Snippets, but inserted literally.

enter image description here

  • /facepalm... After using sed repeatedly you'd think that would've popped into my head. It works, thank you very much. – Kevin Ruffus Jun 26 '16 at 20:28
  • If this answer solved your problem, please accept it by clicking the grey round check button on its left. You mark your problem as solved that way. Please don't forget to invest two minutes to take our little tour as well, where you can learn the basics about how our site works. Thanks and welcome to Ask Ubuntu :-) – Byte Commander Jun 26 '16 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.