Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I have some directory names such as : Bruce Springsteen & the E Street Band. There are spaces between each word. Directory Music contains : Bruce Springsteen & the ...
  1. #1
    xuo
    xuo is offline
    Just Joined!
    Join Date
    Oct 2006
    Posts
    29

    How to put in a tcsh variable a list of directories containing spaces

    Hi,

    I have some directory names such as : Bruce Springsteen & the E Street Band.
    There are spaces between each word.

    Directory Music contains :
    Bruce Springsteen & the E Street Band
    The Rolling Stones

    I would like to put my directory names in a shell variable :
    set listOfDirs = `ls Music`

    foreach data ($listOfDirs)
    echo $data
    end

    As there are spaces (and moreover the & character), it does not work. I get :
    Bruce
    Springsteen
    &
    the
    ...

    How can I get the complete directory name, eventhough it contains spaces and special characters.

    Thanks.

    Eric.

    PS : I could rename the directories, but how can I do it by script ().

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Code:
    set listOfDirs = (Music/*/)
    @ idx = 1
    while ($idx <=  $#listOfDirs)
    	echo "$listOfDirs[$idx]"
    	@ idx ++
    end

  3. #3
    xuo
    xuo is offline
    Just Joined!
    Join Date
    Oct 2006
    Posts
    29
    Hi,

    This helped me a lot. Thanks for your help.

    Eric.

Posting Permissions

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