Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, I am trying something like thi: ls -1 | less The command displays all the files but i inserts crazy looking characters as shown below: ESC[01;34mDesktopESC[00m ESC[00;32mdjvulibre-3.5.17-1-win32.zipESC[00m ESC[01;34mDocumentsESC[00m ESC[01;34mdownloadsESC[00m ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    3

    Unwanted characters while redirecting output of shell commands

    Hello,

    I am trying something like thi:
    ls -1 | less

    The command displays all the files but i inserts crazy looking characters as shown below:

    ESC[01;34mDesktopESC[00m
    ESC[00;32mdjvulibre-3.5.17-1-win32.zipESC[00m
    ESC[01;34mDocumentsESC[00m
    ESC[01;34mdownloadsESC[00m

    I think bash is using carriage return instead of newline. But I am not sure ...
    Does anyone know how to fix this ?

    The problem is not seen when I use sh. Talking about sh, which file is used to store shell settings (i know bash uses .bashrc). I tried .profile and .shrc but neither of them is working.

    Thanks
    J

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    > ESC[01;34m...ESC[00m

    looks a lot like a string used to set the prompt
    PS1--I have \033[1;44m\$\033[0m

    what is your PS1? (echo $PS1)
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    Sep 2007
    Posts
    3
    (Wed Sep 12 11:39:32)~> echo $PS1
    (\d \t)\w>

    It contains date time and current working directory. I had changed it some time back, but the problem was present even b4 this change was made
    The lines in my .bashrc doing this are:

    #export PS1='$(ppwd \l)\u@\h \w> '
    export PS1='(\d \t)\w> '

    Thanks,
    Alok

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Does your regular ls output (not piping to less) appear colored and without those characters?

    What I believe is the problem is that those characters are the color output of ls, and less doesn't know how to handle them. In fact, looking at the less man page mentions that -R option, which tells less to output color control characters. Do you have your "less" command aliased to "less -R"?
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    Just Joined!
    Join Date
    Sep 2007
    Posts
    3
    Hmmmm that seems to be the problem. I disabled --color=always option and now things are looking fine....

    Thanks Cabhan for the suggestion...

Posting Permissions

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