Bash脚本打印命令,但不打印echo命令
发布时间:2020-12-16 01:34:27 所属栏目:安全 来源:网络整理
导读:我想写一个打印命令的bash脚本.但出于可读性目的,我不希望它打印echo命令.不幸的是,我找不到正确的bash脚本设置来实现这一点.我需要帮助? #!/bin/bash# Makes the bash script to print out every command before it is executedset -vecho "Cleaning test
我想写一个打印命令的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 "" 每次命令后都会执行调试.
所以陷阱只是检查最后一个命令是否没有以echo开头并打印出来. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |