[clug] Bash questions...
steve jenkin
sjenkin at canb.auug.org.au
Sat Apr 30 19:39:06 MDT 2011
Yesterday I wanted a short bash construct to write a line of dashes to
separate blocks of output, ie:
--------------------------------------------------
blah blah blah
--------------------------------------------------
yaddah yaddah yaddah
--------------------------------------------------
and so on
--------------------------------------------------
But without doing my usual, v. simple:
echo "--------------------------------------------------" :-)
The bash on my Mac is not-quite-recent, so I can't use 'seq', but the
older form:
for i in {1..10};do ....;done
steve$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Attempt 1:
steve$ for i in {1..20};do echo -n "-";done;echo
Attempt 2:
steve$ yes -|head -20|tr -d '\n';echo
2A:
steve$ yes ''|head -20|tr '\n' '-';echo
2B:
steve$ printf "%s\n" $(yes ''|head -20|tr '\n' '-')
I thought of using 'dd if=/dev/zero bs=1 count=20', but that's a bit long...
=> Someone out there is CLUG land is going to have a great little recipe
for this and related tasks...
Perhaps something with the shell variable pattern matching, or the
string 'expr'??
A recursive function, if it doesn't blow up the stack, could be very short.
Preloading a variable with a very long string, then somehow pulling out
a substring could also work. [There's "array variable BASH_REMATCH"]
python/perl/sed one-liners are also welcome :-)
And "for extra credit", any new interesting thing you've been doing :=]
--
Steve Jenkin, Info Tech, Systems and Design Specialist.
0412 786 915 (+61 412 786 915)
PO Box 48, Kippax ACT 2615, AUSTRALIA
sjenkin at canb.auug.org.au http://members.tip.net.au/~sjenkin
More information about the linux
mailing list