프로그램 상에서 alias 설정.

서지훈의 이미지

int setenv(const char *name, const char *value, int overwrite); 와 같은 alias를 설정해주는 방법이 있나요 ?
현재 좀 찾고 있으나 보이질 않네요.
찾다가 안되면 좀 우회를 해야 할거 같은디 ㅡㅡㅋ

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

harisoo의 이미지

특정 단어를 입력시 위 함수로 채우시겟다는건가요??

그렇다면

#define test_fun int setenv(const char *name, const char *value, int overwrite);

선언하시고 코드상에서 호출 하시면 됩니다..

test_fun;

int main(){
processing something....
}

메크로이기때문에 컴파일할 때 바꿔서 넣어주는거죠

wariua의 이미지

shell의 aliasing 기능을 다른 코드 내에서 동적으로 제어할 수 (가령 아래 코드와 같이) 있는가 하는 걸 물으신 거라면...

setalias("do_it", "/path/to/a/executable/with/very/long/path --and --very-very --many-options");
system("do_it more_param");

어렵지 않을까 합니다. 말 그대로 shell에서 제공하는 기능이까요. .bashrc던가 .bash_profile이던가를 만져주는 식이 되어야 하지 않을까 싶고, 더불어 manpage의 다음 문구를 유의하셔야 할 것 같습니다.
man bash wrote:
ALIASES

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below).


----
$PWD `date`

$PWD `date`

코퍼스의 이미지

음.. 좀 더 구체적인 용도를 알려주세요

ls -al 'happy' | grep 'possible'

A few Good Man

서지훈의 이미지

외부 프로그램(path없이 실행 파일명만)을 system()으로 실행시 aliasing된 파일이 실행 되도록 하게 하는것입니다.
정 안되면 path를 변경 해주고 하는 방법도 있기는 한데 aliasing이 제일 깔끔할것 같아서 고민을 좀...
그러나... 이 고민... 다른 분한테로 넘어가서 지금은 액셀 VBA 보고 있습니다.

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <beer.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);