Screwy Characters or Inferior Command?

OK, I have a script (someScript.sh) which contains some variables somewhere in it:

...
thisIsSomeVariable=someValue
...
anotherSomeVariable=someValue2
...

When I do this piped command:

grep SomeVariable= someScript.sh | cut -d"=" -f2

I get this output:

someValue
someValue2

However, when I do this:

echo `grep SomeVariable= someScript.sh | cut -d"=" -f2`

I just get

someValue2

With some of my better scripts, I get this correct output:

someValue someValue2

When I make use of this info, it somehow manages to toss in some "\b" characters and screws up the output of what I was trying to do. One person suggested that this may be due to the script being written on a windows machine and then being SFTPed into Linux. I've run vim and I can't find a single character that's screwed up. I can't use dos2unix because I don't have permission to install it. Can anyone please let me know of a different command that I can do to make this spaced values effect without the other values being chopped off? I'll be doing this to pass these values into an array.

All responses will be greatly appreciated.

try:

:set ff=unix

You can use Perl. After you SFtp the script to Linux and before you run the "grep" command, do this -

perl -pi.bak -e 's/\r//g' someScript.sh

The weird output of the grep command is due to the "carriage return" character "\r" (ASCII decimal 13), which moves the cursor to the first position of the same line thereby forcing the 2nd line to overwrite the first line. (The "\r" comes from files created in Windows.)

$
$ echo `grep SomeVariable= someScript.sh | cut -d"=" -f2`
 someValue2
$
$ echo `grep SomeVariable= someScript.sh | cut -d"=" -f2` | od -bc
0000000 163 157 155 145 126 141 154 165 145 015 040 163 157 155 145 126
          s   o   m   e   V   a   l   u   e  \r       s   o   m   e   V
0000020 141 154 165 145 062 015 012
          a   l   u   e   2  \r  \n
0000027
$
$

So -

$
$ # Using Perl to remove the carriage return characters
$
$ perl -pi.bak -e 's/\r//g' someScript.sh
$
$ echo `grep SomeVariable= someScript.sh | cut -d"=" -f2`
someValue someValue2
$

The ".bak" backs up your script before applying the changes.

HTH,
tyler_durden

Darn those \r characters! Found em. Thanks again.