simple utilities for making it easier to code from the shell

Get your foo on.

simple utilities for making it easier to code from the shell

Postby fig1 » December 5th, 2015, 6:30 pm

ive been thinking about the tasks i perform most often in bash, and of making a few utilities to create shortcuts.

bash is a great language i use every day, though im not an expert. so these utilities will not replace bash, but for me they augment it.

they can also be used to teach coding.

the first of these utilities is called arrlen, which takes stdin and returns the length of each line. yes, you can do this with a bash one-liner; ive chosen fig (its not too slow for my purposes.)

p=$(echo hello | arrlen | awk '{print $1}') ; echo $p
5


$ for p in $(echo "hello there how are you?") ; do echo $p ; done | arrlen
5 hello
5 there
3 how
3 are
4 you?
$


Code: Select all
#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/

function re(z p)
f=z ; split(f p) ; join(f "") ; return(f)
fig

forin (p stdin)
cr=13 ; chr
lf=10 ; chr
z=p ; re(z cr) ; re(z lf)
p=z ; len ; prints ; " " ; prints
p=z ; print
next
User avatar
fig1
 
Posts: 41
Joined: September 14th, 2015, 4:27 am

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x