Find the answer to your Linux question:
Results 1 to 3 of 3
I were trying to add an alias to my .bashrc file. My mistakes was to write alias ls=`ls --color` instead of alias ls='ls --color' (I noted the difference between ' ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Location
    Bassano, Italy
    Posts
    6

    [SOLVED] playing with ls `ls`

    I were trying to add an alias to my .bashrc file.
    My mistakes was to write alias ls=`ls --color` instead of alias ls='ls --color' (I noted the difference between ' and ’ or `) . The result was surprisingly different , with the wrong alias I got the same output as issuing ls `ls --color`

    Code:
    luca@Amilone:~$ ls `ls --color`
    ls: impossibile accedere a 2INF.pdf: Nessun file o directory
    ls: impossibile accedere a 3INF.pdf: Nessun file o directory
    ls: impossibile accedere a Azureus: Nessun file o directory
    ls: impossibile accedere a Downloads: Nessun file o directory
    ls: impossibile accedere a Desktop: Nessun file o directory
    ls: impossibile accedere a Immagini: Nessun file o directory
    ls: impossibile accedere a informatica: Nessun file o directory
    ls: impossibile accedere a music: Nessun file o directory
    ls: impossibile accedere a plasma_output: Nessun file o directory
    ls: impossibile accedere a plasma_output~: Nessun file o directory
    ls: impossibile accedere a studio: Nessun file o directory
    ls: impossibile accedere a surf: Nessun file o directory
    ls: impossibile accedere a workspace: Nessun file o directory
    ls: impossibile accedere a : Nessun file o directory
    luca@Amilone:~$
    Mmmh... Strange no?
    The ls man pages tell me nothing about this. Could this be an unwanted behaviour ? Or maybe a cool side effect? Or is this the normal behaviour for bash?

    sorry for italian output, read it
    ls: can't access at (file contained in home dir): No such file or directory

  2. #2
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Hi Luca,
    the explanation is easy....
    The back tick executes the shell expression, so...
    Code:
     ls --color gives  (in my home) as output  0001 etc...
    (0001 is actually the first file in my home directory), but 
    the true output is :
     .[00m.[00m0001.[00m.
    as you can see from:
    ls --color |head -n 1 |hexdump -C
    
    00000000  1b 5b 30 30 6d 1b 5b 30  30 6d 30 30 30 31 1b 5b  |.[00m.[00m0001.[|
    00000010  30 30 6d 0a                                                         |00m.|
    00000014
    So obviously the execution of ls `ls --color` generates a series of error messages.
    Ciao.

  3. #3
    Just Joined!
    Join Date
    Feb 2009
    Location
    Bassano, Italy
    Posts
    6
    Oh, Thanks a lot ! now I understand
    so the ls command doesn't print on screen its entire output ? right?

Posting Permissions

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