![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|