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