4

我正在编写一个 .sh 脚本,如下所示:

echo script started
./some_command > output_file
echo script ended

我希望输出如下:

script started   
./some_command > output_file   
script ended  

我试过了set -vset +v但它不能正常工作,
有没有类似@echo批量的东西?

谢谢

4

3 回答 3

7

使用bash -x@TopGunCoder 的评论:

#!/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
于 2013-09-25T20:45:55.807 回答
-1

而不是只用不显示回声的方式echo替换它,你仍然会得到一些反馈#

于 2013-09-25T20:48:03.347 回答
-3

这可以满足您的要求:

#!/bin/bash

echo "script started"
echo "./some_command > output_file"
./some_command > output_file
echo "script ended"
于 2013-09-25T20:31:04.730 回答