The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get command alias name in perl script? ktmchen Shell Programming and Scripting 4 01-15-2008 08:14 AM
How to set alias and ps1 in a script SpringRubber Shell Programming and Scripting 2 05-23-2007 12:53 PM
Auto answer ( Yes or No) from unix script Nayanajith Shell Programming and Scripting 3 08-22-2006 01:29 AM
Bourne: How to invoke an alias from within a shell script techshots Shell Programming and Scripting 2 06-04-2006 12:38 AM
Query regarding alias and setting bash as a default script VENC22 UNIX for Dummies Questions & Answers 1 07-13-2005 09:18 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 12-24-2005
coolboarderguy coolboarderguy is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 7
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0