-
-
Save willb/5c93b09176e006a2cd991ba9f2faf8e5 to your computer and use it in GitHub Desktop.
Revisions
-
Sophie Watson created this gist
Dec 2, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ #!/bin/sh while getopts ":if:" opt; do case $opt in f) useFile=$OPTARG ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; :) echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; i) inPlace=true ;; esac done if [ -n "$inPlace" ] && [ -z "$useFile" ]; then echo "Error: Option -i depends on option -f" >&2 fi if [ -n "$inPlace" ]; then tmpFile=`mktemp` fi # Eval each line and redirect to tmpFile if set, otherwise to process stdout while read -r line; do eval "echo $line" >> "${tmpFile:-/proc/${$}/fd/1}" done < "${useFile:-/proc/${$}/fd/0}" # Overwrite file if [ -n "$inPlace" ]; then mv -- $tmpFile $useFile fi