Skip to content

Instantly share code, notes, and snippets.

@yaronuliel
Created May 26, 2016
Embed
What would you like to do?
#!/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