#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    16
    Rep Power
    0

    'cat' and 'echo' advice: how to show a file in 'cat' format instead of 'echo'


    Hello,

    I'm writing a script that displays a current file I have in the pwd. The script line reads:

    echo `cat movdb.dat`;;

    (It's inside a case statement)

    Anyway, echo displays the contents of the file with single spaces, between words and characters and such.

    If I were to cat the file directly from the cmd line, such as :

    $ cat movdb.dat

    then it would have all the spacing that makes it look nice. But when I do it with echo, it does not include all the spaces and such. How can I make it so it looks like when I exe. "cat movdb.dat" from the cmd line?

    Thank you.

    -vi
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    103
    Rep Power
    14
    Instead of:
    echo `cat movdb.dat`;;
    use:
    `cat movdb.dat` ;;

    Make sure to use backticks ( ` ) and not single quotes.
    Backticks should tell your shell to execute this command.
    You may need to use the full path to cat. Eg: /bin/cat
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    16
    Rep Power
    0
    ah damn, so simple.

    thanks for the revelation.

    -vi
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    16
    Rep Power
    0
    hmm. it does not work, but i think i know why.

    the particular file i am trying to cat has spaces. anyway, i changed the program to:

    `cat movdb.dat`

    ( this is a movie database program i am trying to create, and i'm supposed to list this dat file which i created )

    but when i do that, it says this:

    ./prog6: 0001|Lord: command not found


    its trying to cat the information in that movdb.dat file, but when it hits the first "space" or "blank" ( blank space ) it gets that error.

    any suggestions now ?

    btw, the file is in the same directory, so i won't need the full pathname.

    #####
    also, the first line of the movdb.dat file is:
    0001|Lord of the Rings |Bilbo Baggins |Action |12/12/52| 900000
    #####


    -vi
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    121
    Rep Power
    14
    Lose the backticks. To display a file just use:
    cat movdb.dat

    Add in the semicolons if you want to terminate the case selection on the same line. If you got the cat command to work on the command line, why are you screwing around with echo and backticks in the script?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    16
    Rep Power
    0
    Originally Posted by Perderabo
    Lose the backticks. To display a file just use:
    cat movdb.dat
    Excellent. It finally displays it just the way I want it.

    Originally Posted by Perderabo
    If you got the cat command to work on the command line, why are you screwing around with echo and backticks in the script?
    I thought backticks where needed whenever you need something to execute on the cmd line. 'echo' was truly a intellectual blunder on my part, however, since I echo everything. Thanks for your help, in case you didn't know, i'm new to UNIX scripting .

    Currently in taking an Intro to UNiX class, and its my last program for this semester.

    -vi

IMN logo majestic logo threadwatch logo seochat tools logo