nash
nash copied to clipboard
proposal: Support function invocation when evaluating arguments
fn files(pat, dir) {
IFS=("\n")
results <= ls $dir | grep $pat
return $results
}
λ> mv -v files("png$", ".") ./Images/
'2016-03-10-183202_1802x1080_scrot.png' -> 'Images/2016-03-10-183202_1802x1080_scrot.png'
'2016-07-26-120239_1797x997_scrot.png' -> 'Images/2016-07-26-120239_1797x997_scrot.png'
mv -v files("png$", ".") ./Images/
# must expand to
mv -v ("2016-03-10-183202_1802x1080_scrot.png" "2016-07-26-120239_1797x997_scrot.png") ./Images
# and then applying list eval
mv "2016-03-10-183202_1802x1080_scrot.png" "2016-07-26-120239_1797x997_scrot.png" ./Images