GithubHelp home page GithubHelp logo

whiteblackgoose / forall.bash Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 61 KB

Simple bash command which maps the given list of elements through the given command

License: Creative Commons Zero v1.0 Universal

Shell 100.00%

forall.bash's Introduction

forall

demo

Installation

Download and make it executable:

wget https://raw.githubusercontent.com/WhiteBlackGoose/forall.bash/main/forall
chmod +x forall

Add it to your "$PATH":

echo 'export PATH="yourfolder:$PATH"' >> ~/.bashrc

Docs

Automates simple loops. Basically maps the given 
elements through the given function.

The first argument is list of elements (must be o
ne argument, not multiple).

The second argument is the command to execute (al
so must be one string).

By default it only executes the given command, by
providing each element of the list as the last ar
gument.

Arguments (provide as third argument without dash):

    i: provide each element as standard input inste
       ad of providing it as the last argument.

    p: print the each element next to correspondi
       ng output. (by default only runs the prompt)

Examples

Ex. 1

forall "$(ls -Cb)" "du -sh"

Runs the command du -sh for all folders in the given folder:

~/VirtualBox VMs
12:06:29 $ forall "$(ls -Cb)" "du -sh"
6,7G	archcraft
11G	Linux Mint
8,0K	test
88K	ubuntu 4.10
9,2G	ubuntu mate

Ex. 2

forall "10+3 12-11 'scale=3; 100/3'" bc i

i means that we pipe each element into the given command bc. Output:

~/VirtualBox VMs
12:38:02 $ forall "10+3 12-11 'scale=3; 100/3'" bc i
13
1
33.333

Ex. 3

Let's add p to print each input:

forall "10+3 12-11 'scale=3; 100/3'" bc ip

Output:

~/VirtualBox VMs
12:38:50 $ forall "10+3 12-11 'scale=3; 100/3'" bc ip
10+3: 13
12-11: 1
scale=3; 100/3: 33.333

forall.bash's People

Contributors

whiteblackgoose avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.