User Tools

Site Tools


bash-stdin-or-filename

This is an old revision of the document!


Bash Stdin or Filename

If you write a shell script and want it to run with either stdin or a filename, like so:

  cat text.txt | script.sh
  script.sh text.txt

There are some options:

script.sh
#!/usr/bin/env sh
awk -F, '...' "${1:-/dev/stdin}"
script.sh
#!/usr/bin/env sh
cat "$@" | awk -F, '...'
script.awk
#!/bin/awk -f
BEGIN{FS=","} ...
bash-stdin-or-filename.1706858386.txt.gz ยท Last modified: 2024/02/01 23:19 by dblume