如何将sh脚本命令保存在日志文件中?
我的命令是:bash test.sh
如何使用test.sh命令将命令上下文'bash test.sh'保存到logfile?
动机:当我使用test.sh进行很长的参数解析时(例如,bash test.sh -a -b -c -d .... - -S ....- -s),我必须用不同的论点解析。因此,我想通过参数解析自动保存这些命令。
请注意,echo bash test.sh -a - b ...> log.txt&&& bash test.sh -a -b ...
也可以做。但是,我不想每次重新重新运行test.sh.s.键入如此长的命令。因此,如果有任何简单的方法来解决问题,我会寻求帮助。
我试图修改test.sh作为以下内容,并运行bash test.sh -a -b ...
无法保存上下文bash test.sh -a-- -b ...
to log.txt。
HISTFILE=~/.bash_history
set -o history
history 10 > ./log.txt
functional commands...
My command is: bash test.sh
How to save the command context 'bash test.sh' to logfile using the command with test.sh?
Motivation: When I use the test.sh with very long argument parsing (e.g., bash test.sh --a --b --c --d .... --s) and I have to rerun the command with different argument parsing. Therefore, I want to automatically save these commands with argument parsing.
Note that echo bash test.sh --a --b ... >log.txt && bash test.sh --a --b ...
can do as well. However, I don't want to type in such long command every time I rerun the test.sh. So I ask for help if there is any simple way to fix the problem.
I have tried to modify test.sh as the following, and running bash test.sh --a --b ...
can not save the context bash test.sh --a --b ...
to log.txt.
HISTFILE=~/.bash_history
set -o history
history 10 > ./log.txt
functional commands...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
echo“!bash”> your_file
它将用bash
进行最后的cammand,然后将其写入文件,您可能需要>>
而不是单个>
echo bash test.sh>>>之前将其写入文件。 your_file&& bash test.sh
echo "!bash" > your_file
which would fetch last cammand withbash
and write it to file, you might want>>
instead of single>
echo bash test.sh >> your_file && bash test.sh