Score:2

How can I hide executed commands run from a Makefile script and only show the output?

ec flag

I have a Makefile script with a task containing an rsync statement, when I run the script it outputs the actual rsync command and the response from the rsync command. I want to hide the command and only show the response OR if possible style the rsync command. How can this be done?

See the code below, I've managed to style some of it as you can see. (FYI: I've left out a bunch of tasks etc, and yeah I know this is some old school stuff :) )

# Load environment variables from .env file
include .env

# Define ANSI colors
GRAY=\033[0;37m
NC=\033[0m

# Define default target
.PHONY: deploy
deploy:
    @echo " Starting deployment."
    rsync -azP --delete --exclude-from=.deployignore --checksum --no-perms  -e "ssh -p $(SSH_PORT)" $(LOCAL_PATH) $(SSH_USER)@$(SSH_HOST):$(REMOTE_PATH) | awk '{print "${GRAY}> " $$0 "${NC}"}'
    @echo "✅ All modified files have been deployed."

And of course, I'm running it using make deploy.

I'm using Ubuntu 20.04 but I would very much like this to work on recent Mac OS versions as well.

Thanks!

Richard B avatar
ec flag
Sorry, Ubuntu 20.04.
Richard B avatar
ec flag
But I would very much like this to work on Mac OS (recent versions) as well if possible.
ar flag
Please add how you invoke the script. If the script is called `myscript`, do you type `myscript` in the terminal or `bash myscript` or something else?
Richard B avatar
ec flag
Ok thanks for the comments! It's a Makefile, I didn't think that would matter but I realise maybe it does. I will edit my question.
Score:2
vn flag

There are several ways to run commands "silently" in a makefile.

  1. Prefix the particular command with @, like: @rsync -azP ... (you already did this with the @echo commands).

  2. Add the special target .SILENT to your makefile, like:

    # Define default target
    .SILENT:
    .PHONY: deploy
    deploy:
    
  3. Run make with the -s or --silent parameter.

See here for more info.

hr flag
+1 ... GNU `make` also has `-s, --silent, --quiet` options to quieten globally
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.