For an assignment I am asked to cleverly write a bash function which has the same basic functionality as the function cpcp (copy). It only has to copy one file to another, so no multiple files copied to a new directory.
Since I am new to the bash language, I can't understand why my program is not working. The original function asks to overwrite a file if it is already present, so I tried to implement that. It fails.
The file fails at multiple lines it seems, but most importantly at the condition where it checks if the file to be copied to already exists ([-e "$2"][-e "$2"]). Even so, it still shows the message that is supposed to be triggered if that condition is met (The file name ...).
Could anyone help me in fixing this file, possibly providing some useful insight in my basic comprehension of the language? The code is as follows.
#!/bin/sh
echo "file variable: $2"
if [-e file]&> /dev/null
then
echo "The file name already exists, want to overwrite? (yes/no)"
read | tr "[A-Z]" "[a-z]"
if [$REPLY -eq "yes"] ; then
rm "$2"
echo $2 > "$2"
exit 0
else
exit 1
fi
else
cat $1 | $2
exit 0
fi