PDA

View Full Version : cat issue



quo
05-30-2012, 12:29 PM
In my bash script I want to save the output of a cat command in a variable.I do the following:


var1=`cat outtemp | sed '1d' `

echo $var1

it keeps returning error.why is that?

the error is

var1=12866: Command not found.
var1: Undefined variable.

anduril462
05-30-2012, 01:05 PM
Not sure, it seems to work on my system:


$ cat outtemp
this
is
a
test
$ var1=`cat outtemp | sed '1d' `
$ echo $var1
is a test


Can you post your whole shell script? Also, post the contents of outtemp and any other files if possible.

quo
05-30-2012, 01:15 PM
Not sure, it seems to work on my system:


$ cat outtemp
this
is
a
test
$ var1=`cat outtemp | sed '1d' `
$ echo $var1
is a test


Can you post your whole shell script? Also, post the contents of outtemp and any other files if possible.

ok forget about the sed to make it more simple.
In outtemp there's one string

John.Green

var1=`cat outtemp`
echo $var1

it keeps returning the same error
the simple cat command works but the problem occurs when I store it in the variable

ps.I have nothing else in my script,I just wanted to test this first :)

anduril462
05-30-2012, 02:26 PM
Still works for me on my system.

Describe your system for me. What OS and version? What shell and version are you using? How are you running this (i.e. from a shell script -- text file with #! at the top and execute permissions) or directly from the command line? Try it both ways. Do you get the same error both ways? What other info can you provide that would help me help you.

quo
05-31-2012, 01:05 AM
Still works for me on my system.

Describe your system for me. What OS and version? What shell and version are you using? How are you running this (i.e. from a shell script -- text file with #! at the top and execute permissions) or directly from the command line? Try it both ways. Do you get the same error both ways? What other info can you provide that would help me help you.

thank you so much for mentioning that because I just realized my stupid mistake,I forgot to put the !
I had instead #/bin/bash
Thanks a lot,can't believe it was just this:o