Skip to content

Instantly share code, notes, and snippets.

@thatseeyou
Last active March 15, 2016 08:17
Show Gist options
  • Save thatseeyou/b36e226a0b73a2a3a8a2 to your computer and use it in GitHub Desktop.
Save thatseeyou/b36e226a0b73a2a3a8a2 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "$2" ];then
echo "Usage: $(basename $0) <DIR1> <DIR2>"
echo " $(basename $0) /home/exercise/src /home/exercise/dst"
exit 1
fi
DIR1=$1
DIR2=$2
( cd "$DIR1"; find . ) > /tmp/dir1
( cd "$DIR2"; find . ) > /tmp/dir2
#diff -u /tmp/dir1 /tmp/dir2
diff --old-group-format='%<' \
--new-group-format='%>' \
--unchanged-group-format='' \
--changed-group-format='%<%>' \
--old-line-format='SRC: %L' \
--new-line-format='DST: %L' \
/tmp/dir1 /tmp/dir2
#!/bin/bash
if [ -z "$2" ];then
echo "Usage: $(basename $0) <DIR1> <DIR2>"
echo " $(basename $0) /home/exercise/src /home/exercise/dst"
exit 1
fi
DIR1=$1
DIR2=$2
#diff -u /tmp/dir1 /tmp/dir2
diff --old-group-format='%<' \
--new-group-format='%>' \
--unchanged-group-format='' \
--changed-group-format='%<%>' \
--old-line-format='SRC: %L' \
--new-line-format='DST: %L' \
<(cd "$DIR1"; find .) <(cd "$DIR2"; find .)
#!/bin/bash
if [ -z "$2" ];then
echo "Usage: $(basename $0) <DIR1> <DIR2>"
echo " $(basename $0) /home/exercise/src /home/exercise/dst"
exit 1
fi
DIR1=$1
DIR2=$2
#diff -u /tmp/dir1 /tmp/dir2
echo "--- $DIR1 only ---"
diff --old-group-format='%<' \
--new-group-format='' \
--unchanged-group-format='' \
--changed-group-format='%<' \
--old-line-format='%L' \
<(cd "$DIR1"; find .) <(cd "$DIR2"; find .) | sed -e "s/^.//" | awk "{printf \"%s%s\n\", \"$DIR1\", \$0}"
echo "--- $DIR2 only ---"
diff --old-group-format='' \
--new-group-format='%>' \
--unchanged-group-format='' \
--changed-group-format='%>' \
--new-line-format='%L' \
<(cd "$DIR1"; find .) <(cd "$DIR2"; find .) | sed -e "s/^.//" | awk "{printf \"%s%s\n\", \"$DIR2\", \$0}"
#!/bin/bash
#
# HTTP request without external programs
#
HOSTNAME=www.naver.com
URL='/'
# 1. open tcp
exec 3<>/dev/tcp/${HOSTNAME}/80
# 2. send request
# IMPORTANT "Connection: close"
CR=$'\x0d'
REQUEST="GET ${URL} HTTP/1.1${CR}
Host: ${HOSTNAME}${CR}
Connection: close${CR}
User-Agent: bash${CR}
Accept: */*${CR}
${CR}
"
# double quote preserves \n
1>&3 echo "$REQUEST"
# using cat
if false;then
<<-EOF 1>&3 cat
GET ${URL} HTTP/1.1${CR}
Host: ${HOSTNAME}${CR}
Connection: close${CR}
User-Agent: bash${CR}
Accept: */*${CR}
${CR}
EOF
fi
# 3. receive response
#<&3 cat
#while read line;do echo "$line";done <&3
while read -u 3 line;do echo "$line";done 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment