bash func-如何将函数前面的参数作为参数

bash func-如何将函数前面的参数作为参数,bash,Bash,请重新命名这篇文章,如果你能帮我找到一个更准确的标题 以下是我的bashrc中的内容: export currdate=`date | awk '{print $2$3}'` loggit (){ $0 2>&1 | tee /tmp/$currdate.logs } 基本上,我希望在运行myscript.sh时记录输出,如下所示: bash$: myscript.sh 2>&1 | tee /tmp/todaydate.logs 但我不想每次都这么做,我想

请重新命名这篇文章,如果你能帮我找到一个更准确的标题

以下是我的bashrc中的内容:

export currdate=`date | awk '{print $2$3}'`
loggit (){
   $0 2>&1 | tee /tmp/$currdate.logs
}
基本上,我希望在运行myscript.sh时记录输出,如下所示:

bash$: myscript.sh 2>&1 | tee /tmp/todaydate.logs
但我不想每次都这么做,我想要的是

bash$: myscript.sh loggit 
我不知道当函数在一个参数后执行时如何执行,所以请您帮忙好吗

更新 通过执行此操作修复:

loggit (){
       $1 2>&1 | tee /tmp/$currdate.logs
}
loggit (){
       $1 2>&1 | tee /tmp/$currdate.logs
}
多亏了tripleee

bash$: loggit myscript.sh
bash$: loggit myscript.sh
更新 通过执行此操作修复:

多亏了tripleee

bash$: loggit myscript.sh
bash$: loggit myscript.sh

你不能。为什么要这样做,为什么loggit myscript.sh不可接受?您可以尝试使用tee/tmp/$date+%b%m.logs来提高效率,并且根据您的应用程序,使用tee-a。。。为了安全。@tripleee嘿!这很有效,请回答您自己的问题,如果您找到了解决方案,请接受答案。