Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    31

    Unanswered: retain blank spaces

    How do I retain all the blank spaces when I am reading from a file using while..do..done?

    Thnaks in advance

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Just use quotes around the variable
    e.g. no quotes:
    Code:
    # ps -f | while read line 
    > do
    >   echo $line
    > done
    UID PID PPID C STIME TTY TIME CMD
    root 15172 15171 0 08:30 pts/4 00:00:00 -bash
    root 15210 15172 0 08:33 pts/4 00:00:00 ps -f
    root 15211 15172 0 08:33 pts/4 00:00:00 -bash
    And with quotes
    Code:
    # ps -f | while read line
    > do
    >   echo "$line"
    > done
    UID        PID  PPID  C STIME TTY          TIME CMD
    root     15172 15171  0 08:30 pts/4    00:00:00 -bash
    root     15212 15172  0 08:33 pts/4    00:00:00 ps -f
    root     15213 15172  0 08:33 pts/4    00:00:00 -bash

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •