如何在.bashrc中的函数内创建文件/目录

时间:2015-08-07 21:56:28

标签: bash function local-variables

在.bashrc中,我定义了一个函数:mipinfo () {...}

function mipinfo () {
    outfile="~/path/`date +%Y%m%d`_mipinfo"
    printf "%s\n" "$outfile"; touch $outfile
    .....
}

采购.bashrc会导致退出值为0。

在Gnome终端中输入mipinfo,我得到:

~/path/20150807_mipinfo
touch: cannot touch ‘~/path/20150807_mipinfo’: No such file or directory
bash: ~/path/20150807_mipinfo: No such file or directory

我想这与参数$outfile是本地的有关,而不是传递给touch执行生效的调用shell。我意识到要将一个被调用的脚本变量传递回调用shell,需要在该shell中获取被调用的脚本,但我不清楚如何使用bash脚本来解决这个问题(不是C ++) ,here)。

似乎是将相关变量$outfile从函数内传递给调用脚本/ shell(而不是usual opposite)。实际上甚至不确定。 任何指针都非常赞赏...

0 个答案:

没有答案