Code templates are handy and help in finishing codes without error.

I am aware that notepad editors like atom provide code templates for if and for loop for bash.

Also aware that man pages provide assistance in understanding the syntax. For e.g., man $SHELL helps to understand the if and for commands.

But, I was wondering if there is a way to bring code templates into a terminal itself rather than using a code editor? This will help us to be more productive.

Let me give a use case scenario.

For this post to be solved, I wanted to have a for loop and then a if loop encased in that.

So if a template for for loop can be generated by some shortcuts in the terminal such that

for i in **type words here**; do 

    **type words here** 


Then I go inside the for loop template and then click another shortcut for the ```if````

for i in **type words here**; do 

    if [ **type words here**]; then
       **type words here**     


  • 2
    Clarification: I previously posted this question in askUbuntu forum. As I got no reply. I deleted that post and then posting in Unix and Linux forum. So have posted in only one place of StackExchange. May 13, 2020 at 8:36
  • There is a similar feature in some shells called something like "suggestions" (programmable suggestion? automatic suggestion? I can't remember). I think this may be enabled in zsh and in fish. It uses the shell history to find something similar to what you're currently typing. It's definitely not what you're asking for, but, as I said, it's similar.
    – Kusalananda
    May 13, 2020 at 8:45
  • zsh has autosuggestion feature. Aware of it. May 13, 2020 at 8:46


You must log in to answer this question.

Browse other questions tagged .