I want to make a shell script to run VI with sudo if I try to edit a file that I don't have write permissions and for that I created an alias
alias vi=my_script.sh
#!/bin/bash
file=$1
if [ -r $file ]
then
/usr/bin/vi $file
else
sudo /usr/bin/vi $file
fi
However, no matter what, when try to edit, let's say /etc/hosts, I still not being allowed to edit it.
What am I doing wrong?