[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
smart indented HERE docs
From: |
Derek Schrock |
Subject: |
smart indented HERE docs |
Date: |
Sun, 21 Aug 2016 23:47:40 -0400 |
User-agent: |
Mutt/1.6.1 (2016-04-27) |
I believe this would be a feature request however if this already
exists directly in bash please let me know.
With <<- you can indent a here-doc such that all tabs will be removed.
This can be nice for style reasons in your script however to give the
impression of formatting in the here-doc spaces can be added:
....
cat <<- EOF
Testing 1 2 3
Testing 4 5 6
Testing 7 8 9
EOF
...
Keep in mind the above is prefixed with tabs so with <<- all the prefixed
tabs are removed.
Would result with:
Testing 1 2 3
Testing 4 5 7
Testing 7 8 9
Would it be possible to add a new character (+) to the here-doc such
that the number of tabs remove are the number after the closing
delimiter (EOF in the above example):
....
cat <<+ EOF
Testing 0 9 8
Testing 7 6 5
Testing 4 3 2
EOF
Note the above here-doc is tabbed out by two but the closing delimiter
is only tabbed by 1 so only 1 tab is removed.
Would result with:
Testing 0 9 8
Testing 7 6 5
Testing 4 3 2
This would allow you to write here-docs inside functions and continue to
use tabs to maintain proper formatting and not have to use spaces.
- smart indented HERE docs,
Derek Schrock <=