Skip to content

Instantly share code, notes, and snippets.

@yaronuliel
Created May 26, 2016 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronuliel/37ba0cb40a903a71fb7ac2d2c9606783 to your computer and use it in GitHub Desktop.
Save yaronuliel/37ba0cb40a903a71fb7ac2d2c9606783 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ $# -ne 2 ] && [ $# -ne 1 ]; then
echo "use: $0 source <destination>"
exit
fi
if [ ! -f $1 ]; then
printf "\e[31m$1\e[0m does not seem to be a file"
echo
exit
fi
if [ ! -r $1 ]; then
printf "\e[31m$1\e[0m does not seem to be readable"
echo
exit
fi
if [ "$1" == "help" ]; then
echo "Use: $0 source_file <destination_file>"
echo "If destination_file is not set - the source file will be overwritten"
exit
fi
dest=$1
continue="Y"
if [ $# -eq 2 ]; then
dest=$2
else
printf "Source file will be overwritten. Continue? [Y/n] "
read continue
fi
if [[ $continue != "Y" && $continue != "y" && $continue != "" ]]; then
echo "Terminated by user"
exit
fi
DIR=$(dirname "$2")
tmp=`mktemp`
printf '\xEF\xBB\xBF' > $tmp
cat $1 >> $tmp
mv $tmp $dest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment