Thread: cat issue

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    116

    cat issue

    In my bash script I want to save the output of a cat command in a variable.I do the following:

    Code:
    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.
    Last edited by quo; 05-30-2012 at 12:31 PM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Not sure, it seems to work on my system:
    Code:
    $ 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.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    116
    Quote Originally Posted by anduril462 View Post
    Not sure, it seems to work on my system:
    Code:
    $ 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
    Last edited by quo; 05-30-2012 at 01:19 PM.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    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.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    116
    Quote Originally Posted by anduril462 View Post
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Yet another EOF issue
    By kkk in forum C Programming
    Replies: 4
    Last Post: 09-01-2011, 10:52 AM
  2. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  3. DNS issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-02-2008, 10:15 AM
  4. DLL issue
    By crazybucky in forum C++ Programming
    Replies: 1
    Last Post: 04-02-2008, 12:12 PM
  5. dll issue
    By axr0284 in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2006, 08:37 AM