0

I was trying to write a bash script. This is the code I've managed to write.

#!/bin/bash


RED='\033[0;31m'
NC='\033[0m' # No Color

CurrentBranch=$(git rev-parse --abbrev-ref HEAD)
printf("${RED}$CurrentBranch${NC}")

I am storing the current branch value in a variable and trying to print it in red colour, but I'm getting the following error.

1
  • Try the printf without the parantheses: printf "${RED}$CurrentBranch${NC}" Commented Apr 3, 2016 at 18:35

2 Answers 2

1

printf doesn't use parentheses. Try this:

#!/bin/bash


RED='\033[0;31m'
NC='\033[0m' # No Color

CurrentBranch=$(git rev-parse --abbrev-ref HEAD)
printf "${RED}$CurrentBranch${NC}"
Sign up to request clarification or add additional context in comments.

Comments

1

This should be working:

#!/bin/bash


RED='\033[0;31m'
NC='\033[0m' # No Color

CurrentBranch=$(git rev-parse --abbrev-ref HEAD)
printf "${RED}$CurrentBranch${NC}"

There is no need for parentheses in printf.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.