4 ms·
This is equivalent to the following bash incantation?: cat <<eof\ | while read a;do if [[ $a -gt 2 ]];then echo $a;fi; done \ |while read b;do ec
by e12e 12y ago
This is equivalent to the following bash incantation?:
cat <<eof\
| while read a;do if [[ $a -gt 2 ]];then echo $a;fi; done \
|while read b;do echo $((b*2));done
1
2
3
4
5
eof
(Better expressed with seq):
seq 5 \
| while read a;do if [[ $a -gt 2 ]];then echo $a;fi; done \
| while read b;do echo $((b*2));done
But we can do (a little) better:
# Ok, this is a bit odd, the filter is actually inverse...
filter()
{
while read it
do
#NOT SAFE!!
if eval ${*}
then
echo "${it}"
fi
done
}
map()
{
while read it
do
#NOT SAFE!!
eval ${*}
echo "${it}"
done
}
#Valid bash:
seq 5 \
| filter test '$it' -gt 2 \
| map 'it=$((it*2))'
Sorry, didn't mean to turn this into stack overflow, the "simple" syntax
just tickled me...