我正在编写一个 .sh 脚本,如下所示:
echo script started
./some_command > output_file
echo script ended
我希望输出如下:
script started
./some_command > output_file
script ended
我试过了set -v
,set +v
但它不能正常工作,
有没有类似@echo
批量的东西?
谢谢
使用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
而不是只用不显示回声的方式echo
替换它,你仍然会得到一些反馈#
这可以满足您的要求:
#!/bin/bash
echo "script started"
echo "./some_command > output_file"
./some_command > output_file
echo "script ended"