chatuur
chatuur

Reputation: 1277

Bash script syntax

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.

Upvotes: 0

Views: 124

Answers (2)

mvidovic
mvidovic

Reputation: 331

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.

Upvotes: 1

nick.graziano
nick.graziano

Reputation: 678

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}"

Upvotes: 1

Related Questions