Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alias not working when used in shell script

Status
Not open for further replies.

nerbonne

Technical User
Dec 11, 2006
99
US
I'm trying to make a simple shell script which contains a few commands that delete certain files and also set a few aliases since they have to be set every time the user logs in. I know that I could set aliases in the .login file, but this is not an option for me. I would like to be able to type ./setup.sh and have the aliases set for me.

When I type the alias command at the prompt, it works fine for me. But when I run ./setup.sh which contains the exact same command, it does not work?

Here is the alias format that I am using that is working:

alias "alias_here" /folder/subfolder/command.sh > /folder/subfolder/output.txt

also, this is not working either so I don't think it is the >

alias "alias_here" rm -rf /folder/subfolder/*

I'm not terribly familiar with Solaris, but I think it may have something to do with the environment? Again, the commands work from the prompt, but not in the shell script.

Any ideas?
 
I would like to be able to type ./setup.sh and have the aliases set for me.
To get this to work use:
. ./setup.sh
this is called 'sourcing'. It runs the script in your processes space and not in its own process space (where files would be deleted but any aliases that were setup would disappear the moment the script finished).

To get the 'alias' command to work, see the man pages (man alias) where you'll discover there is a different format for Bourne/Korn shells and C shells. I suspect you are in a 'C shell' and run the script in a Bourne/Korn shell (if the first line is #!/bin/sh or #!/bin/ksh)


I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top