Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > scripting the alias command

scripting the alias command
Thread Tools
Registered User
Join Date: Jan 2003
Location: New Brunswick, NJ
Status: Offline
Reply With Quote
Feb 28, 2003, 04:16 PM
 
Anyone know why the below script doesn't work? (I'm not sure how I have the shell line (#!...), but I think I have that right.)

---------------------------
#!/bin/tsch/
alias new "pwd;date;clear"
alias list "clear;ls -F"
echo "test"
----------------------------

The two alias commands work fine outside the script, and when I run the script, the echo command prints out the string. Are there some commands that don't work inside a script?
     
Senior User
Join Date: Jan 2003
Location: Stuttgart, Germany
Status: Offline
Reply With Quote
Feb 28, 2003, 04:42 PM
 
You have "/bin/tsch/" in your script, which is wrong. That should read "/bin/tcsh" (note the missing trailing slash).
But that isn't the culprit: each time you execute that script, a new shell gets started (the one you specified in the first line) and runs through the commands. After everything is said and done, the shell quits. Since those aliases are only setup for this shell, your script can't possibly work. If you want to setup aliases, you should do it in the appropriate init files.

BTW, the level of nested shells is stored in the "SHLVL" environment var.
     
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Mar 1, 2003, 12:57 PM
 
Originally posted by entrox:
You have "/bin/tsch/" in your script, which is wrong. That should read "/bin/tcsh" (note the missing trailing slash).
Is is the trailing slash or the mispelled shell name (tsch) that's causing the errors?
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Mar 1, 2003, 08:16 PM
 
Either define your aliases in one of the init files like entrox told to have your aliases defined for every shell/terminal window you start, or use "source yourfilewithaliasdefinitions" to read them into your current shell only (won't need the #!/bin/tcsh line then).

-
     
Senior User
Join Date: Jan 2003
Location: Stuttgart, Germany
Status: Offline
Reply With Quote
Mar 2, 2003, 04:39 AM
 
Originally posted by [APi]TheMan:
Is is the trailing slash or the mispelled shell name (tsch) that's causing the errors?
Neither one - That was just a tip for the future. I should have said it more clearly.
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 05:46 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2