0

On my gitlab CI I am running the following simple script (.gitlab-ci.yml):

STR=$(cat $FILE)
if grep -q "substring" <<< "$STR"; then echo "ok"; fi

Unfortunatley this gives me the error

/bin/sh: eval: line 100: syntax error: unexpected redirection

Running the same command locally as a script is working as expected:

#!/bin/sh

FILE="./file.txt"
STR=$(cat $FILE)

if grep -q "substring" <<< "$STR"; then
    echo "ok"
fi

The file has the content:

This has a substring somewhere

1 Answer 1

1

/bin/sh is not bash and <<< is a bash extension not available on every shell. Install bash, change shebang to /bin/bash and make sure the script is run under bash or use posix compatible syntax printf "%s\n" "$str" | grep...

Note: UPPER CASE VARIABLES are by convention reserved for exported variables, like IFS COLUMNS PWD UID EUID LINES etc. Use lower case variables in your scripts.

Sign up to request clarification or add additional context in comments.

2 Comments

Im running this in a alpine image. I think there is no bash but sh. How can I check for substring in sh?
or use posix compatible syntax printf "%s\n" "$str" | grep... stackoverflow.com/questions/2829613/… I meant if printf "%s\n" "$str" | grep -q somehthing; then.

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.