Auto Alias Script

Hi All,

as you can guess, I'm a newb here, and to shell scripting. I use Linux(CentOS) at home and want to get into scritping. I was creating some aliases on a Laptop the other day, and thought, god this is tedious, and then I thought, heck, why not use it as a 1st script project. Please see below, my 1st attempt at this. I am particularly interested in the awk statement towards the end, as the script hangs at that point. I am also interested in any good tips, on how to improve the script, but, please, just direct me, don't just post full scripts, as I would rather be challenged in finding the solutions myself. Cheers.

coolboarderguy...

#!/bin/bash
#set variables to zero

aliasName=""
aliasCommand=""
correctyesNo=""
checkdupyesNo=""
bashrc=""
cancelYesNo=""
anotheraliasyesNo=""

#read in aliasNew and aliasCommand via function newAlias

newAlias () {
echo -n "Please insert alias name: "
read aliasName
echo -n "Please insert alias command: "
read aliasCommand

#confirm aliasNew and aliasCommand and append to .bashrc file...also check for duplicate aliases at this point before appending

echo -n "alias $aliasName='$aliasCommand' Is this correct? (Y/N)"
read correctyesNo
echo -n "Do you wish to check for duplicate aliases? (Y/N)"
read checkdupyesNo
case $checkdupyesNo in
No|no|N|n)case $correctyesNo in
Yes|yes|Y|y)echo "alias $aliasName='$aliasCommand'" >> ~/.bashrc ;;
No|no|N|n)return 1 ;;
*)echo "Error, please choose Yes or No" ;;
esac ;;
Yes|yes|Y|y)bashrc = ~/.bashrc
if [-f $bashrc] ; then
awk '
/alias $aliasName='$aliasCommand'/
{echo -n "That alias exists already: Cancel? (Y/N)"}
'
read cancelyesNo
case $cancelyesNo in
Yes|yes|Y|y)newAlias ;;
No|no|N|n)echo "alias $aliasName='$aliasCommand'" >> ~/.bashrc ;;
*)echo "Error, please choose Yes or No" ;;
esac
fi
esac

#ascertain if user wants to create another alias.

echo -n "Do you wish to create another new alias (Y/N)"
read anotheraliasyesNo
case $anotheraliasyesNo in
Yes|yes|Y|y)newAlias ;;
No|no|N|n)return 1 ;;
*)echo "Error, please choose Yes or No" ;;
esac
}

#newAlias function is first called
newAlias

Hi All,

with my 1st post, I was hoping for some festive help. Perhaps my approach was wrong.? Sorry if so. Or, is it that the code is just disasterous, and nobody wants to bother.? Cheers.

coolboarderguy...

Or maybe some of our regulars think this is a holiday or something. While you wait for a response, please read our rules. And note:

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.

Hi All,

yes, I respect that this time of year, is a holiday. Wasn't trying to bump anything up, was just checking whether, perhaps I'd written it with the wrong approach. I would imagine bumping, is just writing something frivilous, to move back up the ladder. That wasn't my intention, at all. Happy season to all. I'll be more careful next time. Cheers.

coolboarderguy...