0

Hi I wanted to write a simple bash script to execute some google cloud commands using the google cloud shell Terminal. Doing this I got always some kind of variable error, so I wrote a simple script to understand what's going on. This is the script:

#! /bin/bash
STR1=string1
STR2=string2
echo $STR1$STR2
echo "My String1= ${STR1} My String2= ${STR2}"

My expected output which I got on my ubuntu terminal was this:

string1string2
My String1= string1 My String2= string2

However when I execute it on cloud shell it looks like this: Cloud Shell Output

For some reason Cloud Shell ignores my first variable. What could be the reason?

  • Something -- probably the version of the script you're running on cloud shell -- has DOS/Windows-style line endings, which is contaminating the variables with carriage returns. See ["Are shell scripts sensitive to encoding and line endings?"](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – Gordon Davisson Apr 22 '22 at 07:44

1 Answers1

0

Thanks to Gordon Davisson. My mistake was that I wrote the script on Windows Notepad. Afterwards I had just uploaded the file into my cloud shell. Looks like the Windows line endings created then an error. I tested it by creating the script right in cloud shell via nano and the error disappeared.