Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Just do this then ...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Just do this then ...
Authored by: buc40 on Jul 30, '02 10:05:22PM

No prob:#!/usr/bin/env python
import os

user = raw_input("Enter username: ")
cmd = raw_input("Enter the CMD you want to make an alias for: ")
alias = raw_input("Enter the alias without quotes: ")
pound = raw_input("Enter a one line description for the alias: ")

file = "/Users/%s/Library/init/tcsh/aliases.mine" % user
output = "# %s n alias %s '%s' n" % (pound, cmd, alias)

fileout = open(file, "a")
fileout.write(output)
fileout.close()

os.system("su %s" % user)


This of course leads a possible security opening open for abuse as
mentioned earlier.

Good Luck.
SA



[ Reply to This | # ]
Re; Just do this then ...
Authored by: hayne on Jul 31, '02 12:17:26AM

Sigh.
This version has exactly the same problem as the original script.
It starts a new (nested) shell and the Python script continues to run as long as you use that shell. If you did this several times, you would have several copies of this Python script running as well as several extra shells.



[ Reply to This | # ]
Re; Just do this then ...
Authored by: buc40 on Jul 31, '02 10:06:13AM

Why not just rehash then instead of su?

Will this work?

SA



[ Reply to This | # ]
Re; rehashing
Authored by: hayne on Jul 31, '02 01:39:37PM

rehashing updates the shell's list of executables.
It does not do anything with aliases.

The solution is relatively simple - you use an alias to perform multiple commands as I suggested earlier. (There is nothing that can be done in a shell script since what you are trying to change is the current shell's environment.)



[ Reply to This | # ]