Auto Alias Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto Alias Script
# 1  
Old 12-24-2005
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
# 2  
Old 12-25-2005
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...
# 3  
Old 12-25-2005
Quote:
Originally Posted by coolboarderguy
Perhaps my approach was wrong.? Sorry if so. Or, is it that the code is just disasterous, and nobody wants to bother.?
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.
# 4  
Old 12-25-2005
Quote:
Originally Posted by Perderabo
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...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Auto-backup script

hello guys i need a script to automatically backup a whole directory in linux like /var/www and the whole sql db and upload to an ftp server daily (as a cron job) is there something like this? I read about rsync but I don't know if it will suit this. (6 Replies)
Discussion started by: galapagos8000
6 Replies

2. Shell Programming and Scripting

How to provide auto inputs for a sub-script within a script?

Hi All, I am writing a shell script. #!/bin/bash cat /etc/hosts mkdir -p /var/tmp mount 113.123.35.37:/vol/vol615/syb /var/tmp In above script I am trying to add below predefined script/command (/var/tmp/db_tools) This command in turn ask for user input, which will be always option... (17 Replies)
Discussion started by: madhur.baharani
17 Replies

3. Shell Programming and Scripting

Alias has no effect in script

It doesn't have effect in script but it works on the terminal root@server:/opt/kvm/usecases/logs# alias echo='echo -e' root@server:/opt/kvm/usecases/logs# echo "xxxx\n" xxxx root@server:/opt/kvm/usecases/logs# cat xx.sh #!/bin/bash alias echo='echo -n' echo "sssf \n" ... (3 Replies)
Discussion started by: yanglei_fage
3 Replies

4. Shell Programming and Scripting

auto kill script

Hi, I have created a shell script which is used by many users to change their password/unlock, etc., via menu. There is possibility users just close the putty window without proper exit from menu. I want a solution so that if anybody forgets to stop that session, it should kill automatically... (9 Replies)
Discussion started by: prashant2507198
9 Replies

5. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

6. Shell Programming and Scripting

Using alias in script

Hi all, Could any one tell me how to use aliases in a script i have a large command which launches an application. I want to use alias in the script because i call the application many time in the shell script. Thanks Firestar. (5 Replies)
Discussion started by: firestar
5 Replies

7. Windows & DOS: Issues & Discussions

auto login script

can any one help me for auto login bat file from windows to unix,to check the server daily.. Thanks Mohan (1 Reply)
Discussion started by: mohankasi
1 Replies

8. UNIX for Advanced & Expert Users

alias command in script

How can I embed alias command inside the unix script? Script: echo "...." ... ... alias aa=/usr/bin/telnet ... ...The above script is not working. If I type aa hostname in the command prompt 'TELNET' terminal is not opening. Regards,... (2 Replies)
Discussion started by: sharif
2 Replies

9. UNIX for Dummies Questions & Answers

Shell Script to Auto Run PHP Script

Hello All! I am looking to build a monitoring script. The script should always run as a system service of some type and should always check that a PHP script is running. Maybe there is a way to assign a PHP script to a certain PID so that the monitor script that check for the PID in top... (4 Replies)
Discussion started by: elDeuce
4 Replies
Login or Register to Ask a Question