Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exec 3<> /tmp/foo # open fd 3.
- echo a >&3 # write to it
- exec 3>&- # close fd 3.
- FILE=/tmp/foo
- echo a > "$FILE"
- while IFS= read -r line; do
- printf '%sn' "$line"
- if IFS= read -r line; then printf '%sn' "$line" >&3; fi
- done >odd.txt 3>even.txt
- { while … done | odd-filter >filtered-odd.txt; } 3>&1 | even-filter >filtered-even.txt
- exec 8<&0 9>&1
- exec >output12
- command1
- exec <input23
- command2
- exec >&9
- command3
- exec <&8
- (
- rm -f fifo
- mkfifo fifo
- exec 3<fifo # open fifo for reading
- trap "exit" 1 2 3 15
- exec cat fifo | nl
- ) &
- bpid=$!
- (
- exec 3>fifo # open fifo for writing
- trap "exit" 1 2 3 15
- while true;
- do
- echo "blah" > fifo
- done
- )
- #kill -TERM $bpid
- #!/bin/bash
- log() {
- echo $* >&3
- }
- info() {
- echo $* >&4
- }
- err() {
- echo $* >&2
- }
- debug() {
- echo $* >&5
- }
- VERBOSE=1
- while [[ $# -gt 0 ]]; do
- ARG=$1
- shift
- case $ARG in
- "-vv")
- VERBOSE=3
- ;;
- "-v")
- VERBOSE=2
- ;;
- "-q")
- VERBOSE=0
- ;;
- # More flags
- *)
- echo -n
- # Linear args
- ;;
- esac
- done
- for i in 1 2 3; do
- fd=$(expr 2 + $i)
- if [[ $VERBOSE -ge $i ]]; then
- eval "exec $fd>&1"
- else
- eval "exec $fd> /dev/null"
- fi
- done
- err "This will _always_ show up."
- log "This is normally displayed, but can be prevented with -q"
- info "This will only show up if -v is passed"
- debug "This will show up for -vv"
- env -i bash --norc # clean up environment
- set +o history
- read -s -p "Enter your password: " passwd
- exec 3<<<"$passwd"
- mycommand <&3 # cat /dev/stdin in mycommand
- arg1 string to echo
- arg2 flag 0,1 print or not print to 3rd fd stdout descriptor
- function ecko3 {
- if [ "$2" -eq 1 ]; then
- exec 3>$(tty)
- echo -en "$1" | tee >(cat - >&3)
- exec 3>&-
- else
- echo -en "$1"
- fi
- }
- #exit if we can't obtain the lock
- set -e
- #open file descriptor 3 for writing
- exec 3> /tmp/file.lock
- #create an exclusive lock on the file using file descriptor 3
- #exit if lock could not be obtained
- flock -n 3
- #execute serial code
- #close the open file handle which releases the file lock
- exec 3>&-
Add Comment
Please, Sign In to add comment