Bash脚本打印命令,但不打印echo命令

我想写一个打印命令的bash脚本.但出于可读性目的,我不希望它打印echo命令.不幸的是,我找不到正确的bash脚本设置来实现这一点.我需要帮助?
#!/bin/bash

# Makes the bash script to print out every command before it is executed
set -v

echo "Cleaning test database"
RAILS_ENV=test bundle exec rake db:drop
echo "************************************************************"
echo ""

echo "Setting up the test database"
RAILS_ENV=test bundle exec rake db:setup
echo "************************************************************"
echo ""

输出如下:

echo "Cleaning test database"
Cleaning test database
RAILS_ENV=test bundle exec rake db:drop
echo "************************************************************"
************************************************************
echo ""


echo "Setting up the test database"
Setting up the test database
RAILS_ENV=test bundle exec rake db:setup

如您所见,它打印出所有命令,包括echo命令,我不想看到它.

你有什么想法?

干杯,

赫拉尔

您可以使用trap DEBUG而不是set -v作为一个选项.

例如

#!/bin/bash


# Makes the bash script to print out every command before it is executed except echo
trap '[[ $BASH_COMMAND != echo* ]] && echo $BASH_COMMAND' DEBUG

echo "Cleaning test database"
RAILS_ENV=test bundle exec rake db:drop
echo "************************************************************"
echo ""

echo "Setting up the test database"
RAILS_ENV=test bundle exec rake db:setup
echo "************************************************************"
echo ""

每次命令后都会执行调试.
$BASH_COMMAND目前正在运行命令.

BASH_COMMAND
The command currently being executed or about to be executed,unless the shell is executing a command as the result of a trap,in which case it is the command executing at the time of the trap.

所以陷阱只是检查最后一个命令是否没有以echo开头并打印出来.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...