Crates.io | arg2stdin |
lib.rs | arg2stdin |
version | 0.1.4 |
source | src |
created_at | 2023-02-28 06:46:26.299617 |
updated_at | 2023-02-28 12:37:57.561866 |
description | A simple utility to pass cli arguments as stdin to a specified command. |
homepage | |
repository | https://github.com/singe/arg2stdin |
max_upload_size | |
id | 796679 |
size | 45,812 |
A simple utility to pass cli arguments as stdin to a specified command.
arg2stdin <command> <string to pass to stdin>
For example:
arg2stdin rev hello
The command doesn't need to be a single command, and can be a long shell one liner too. For example:
arg2stdin 'sed "s/A/X/g" | grep -o "X" | wc' AAAAAAAA
Sometimes you don't want to pass something via stdin, but the command only accepts stdin. For example if I wanted to print the string 'hello' backwards I might try:
rev hello
This will fail because there is no file named 'hello'. Instead, we're supposed to:
echo hello | rev
Wouldn't it be nice to be able to do this instead:
arg2stdin rev hello
Well, ok, it's longer than using echo and pipes, but sometimes you're executing in a way that doesn't give you access to stdin, then it's useful.
The alternative would be something like this (thanks @vhata):
bash -c 'echo "$0 $@" | rev' hello
In which case arg2stdin
makes it a little more intuitive.