Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The following changes for alias are only maintained during the code runtime and goes off when the terminal prompt comes again.

system("alias listing='ls'");

Is there any way around to reflect the changes permanent, without editing the .bashrc or .bashrc_profile.

share|improve this question
2  
If you want the change to be really permanent, you need to edit at least a file, let it be .bashrc or .profile. Otherwise, how should the shell know that it needs to define such an alias the next time it runs? Probably with permanently you actually mean till I close the shell, which is a different problem. –  Andrea Corbellini Jan 9 '13 at 16:09
    
@AndreaCorbellini The goal here is to make a C program that adds a shell alias and terminates, such that the shell alias is non-permanent but exists in the shell that just ran the C program. I see no obvious way to do that but that's a far cry from being sure there's no way to do it. –  Eliah Kagan Jan 9 '13 at 16:15
2  
the only way to do this is to replace the calling bash shell with child process however I'd really avoid doing this. just use profile's to maintain aliases. if you cannot use profiles, then wrap what you need in a shell script. its much better for this sort of thing, C might not be the best choice here. –  strings Jan 9 '13 at 16:31
2  
Don't. Seriously, don't. A compiled program is the worst way to do this. A shell script, the best. You need something that sets aliases in the current shell, and a C program won't let you do that. From the POSIX manpage for system(), "The system() function shall not return until the child process has terminated.". It will be a different shell, and the alias will be lost as soon as system() returns. –  njsg Jan 9 '13 at 19:01
2  
why do you want to do that? Maybe if you try to explain what exactly is that you want to achieve, we'll provide you better ideas. –  elias Jan 9 '13 at 23:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.