我正在编写如下的.sh脚本:
echo script started
./some_command > output_file
echo script ended
我希望输出如下:
script started
./some_command > output_file
script ended
我已尝试过set -v
,set +v
,但它无法正常使用,
批次中有@echo
类似的内容吗?
由于
答案 0 :(得分:7)
使用@TopGunCoder评论中的bash -x
:
#!/usr/bin/env bash -x
echo $0 started > /dev/null
ls
pwd
./some_command > output_file
date
echo $0 ended > /dev/null
OUTPUT是每个命令后跟其结果:
+ echo /Users/myuser/scripts/tbash.sh started
+ ls
[...my directory listing...]
+ pwd
/Users/myuser
+ ./some_command
[the output of "some command"]
+ date
Wed Sep 25 17:06:25 PDT 2013
+ echo /Users/myuser/scripts/tbash.sh ended
答案 1 :(得分:-1)
而不是使用echo
,只需将其替换为#
,这样就不会显示回显并且您仍然可以得到一些反馈
答案 2 :(得分:-3)
这就是你想要的:
#!/bin/bash
echo "script started"
echo "./some_command > output_file"
./some_command > output_file
echo "script ended"