Skip to main content

Embed python expressions in bash

Project description

pyil - PYthon InLine

Simple in Python, but hard in BASH? pyil is here to help!

A small utility to use Python expressions in bash scripts

badge

Installation

$ pip3 install pyil-bin

Examples

Print squares

$ echo nums.txt
1
2
3
$ cat nums.txt | pyil "int(i) ** 2"
1
4
9

pyil evaluates the expression using Python, by default once per each line. The line is provided in i variable to the expression evaluation context (without the trailing \n)

Print only even numbers

$ echo nums.txt
1
2
3
$ cat nums.txt | pyil -g "int(i) % 2 == 0"
2

The -g (--grep) option enables line filtering mode - the expression is not printed, but used to determine if the line should be printed

Usage

usage: pyil [-h] [-l | -g | -t | -n] [-i] [-j] E

Shortcut for using Python for line processing

positional arguments:
  E               expression to evaluate

optional arguments:
  -h, --help      show this help message and exit
  -l, --lines     Evaluate expression once, with the `lines` generator
  -g, --grep      Instead of printing the value use it for filtering lines
  -t, --truish    Print only values where bool(val) == True
  -n, --none      Print only values where val != None
  -i, --iterable  Threat resulting value as iterable of separate lines. Usefull with --lines, ignored with --grep
  -j, --json      Print value using json.dump(). Together with --iterable results in NDJSON, ignored with --grep

More examples

TBD

Please report all bugs to GitLab issues

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyil-bin-0.1.tar.gz (3.4 kB view hashes)

Uploaded source

Built Distribution

pyil_bin-0.1-py3-none-any.whl (4.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page