我想寫一個bash腳本打印命令。但爲了便於閱讀,我不希望它打印回顯命令。不幸的是,我無法找到我的bash腳本的正確設置來實現此目的。我需要幫助?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」' – whoan
Makefile適合你的任務嗎?這是一種截然不同的方法,但是'make'會在執行時默認迴應每個命令,*除非*前綴爲@。 – chepner