January 05 2022, 09:27#
shell - Pipe input into a script - Stack Overflow
Lien : https://stackoverflow.com/questions/19408649/pipe-input-into-a-script/46726373#46726373
Alimenter un script depuis stdin :
#!/bin/bash
# Check to see if a pipe exists on stdin.
if [ -p /dev/stdin ]; then
echo "Data was piped to this script!"
# If we want to read the input line by line
while IFS= read line; do
echo "Line: ${line}"
done
# Or if we want to simply grab all the data, we can simply use cat instead
# cat
else
echo "No input was found on stdin, skipping!"
# Checking to ensure a filename was specified and that it exists
if [ -f "$1" ]; then
echo "Filename specified: ${1}"
echo "Doing things now.."
else
echo "No input given!"
fi
fi
Tags : unix shell script