【发布时间】:2022-01-04 07:53:33
【问题描述】:
我想编写一个 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 命令。
【问题讨论】:
-
也许这个?:
| grep -v "echo " -
Makefile 是否适合您的任务?这是一种截然不同的方法,但
make在执行每个命令时默认回显它,除非您在命令前加上@。
标签: bash command-line echo