0
我目前正在研究一个旨在为任何基本编辑器添加新项目代的脚本。 我才能产生正确的基本程序根据用户选择的语言中使用以下结构(你好,世界):
#!/bin/sh
#this is a short example in the case the user selected C as the language
TXTMAIN="\$TXTMAIN_C"
$TXTMAIN_C="#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const* argv[])
{
printf(\"hello, world\n\");
return EXIT_SUCCESS;
}"
MAIN="./main.c"
touch MAIN
echo -n "$(eval echo $TXTMAIN)" >> "$MAIN"
gedit MAIN
这段代码使您在编辑的main.c以下输出:
#include <stdlib.h> #include <stdio.h> int main(int argc, char const* argv[]) { printf("hello, world\n"); return EXIT_SUCCESS; }
然而,通过更换线13时回声-n “$ TXTMAIN_C” >> “$ MAIN”,它给出正确的输出:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const* argv[])
{
printf("hello, world\n");
return EXIT_SUCCESS;
}
我还是不知道这是一个回声或eval问题,或者是否有解决指针类问题的方法。 任何建议都非常欢迎!
单引号是你的朋友。写起来容易多了:'TXTMAIN_C ='#include ...'因为你不需要转义“或\。 – 2013-02-09 13:43:09