0

I am running a bash script in which one line is this:

VERSION=$(awk -F. '{print $2}' <<< $BISMARK)
VERSION=$(cut -d '.' -f2 <<< $BISMARK )

but getting the following error from this line (when I comment out this line I will not get any error).

Syntax error: redirection unexpected

do you know what the problem is?

John
  • 131
  • 1
  • 2
  • 10
  • 3
    Are you running the script with `bash` or some other shell? How do you run it? – choroba Oct 15 '21 at 12:24
  • Is `$BISMARK` the empty string? The error you see is not the one I would expect, but quotes wouldn't hurt. Always quote your variables, unless there is a specific reason not to. – William Pursell Oct 15 '21 at 12:26
  • 1
    The error message does not look like `bash` but `sh`. Please add output of `echo $BASH_VERSION` to your question. – Cyrus Oct 15 '21 at 12:28

1 Answers1

0

It would seem you are not actually running the script with Bash, but with some other shell instead. Your code works fine for me on Bash, but executing it with BusyBox's ash for example results in the error you mentioned.

What is the first line of your script? It should be either:

#!/bin/bash

or:

#!/usr/bin/env bash

Also, how do you execute the script? If the first line is correct, you should run it like this:

./script.sh

or alternatively like this:

bash script.sh
Fonic
  • 2,625
  • 23
  • 20