Created
May 26, 2016 13:05
-
-
Save yaronuliel/37ba0cb40a903a71fb7ac2d2c9606783 to your computer and use it in GitHub Desktop.
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 characters
#!/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