1

I try to save the ls of an directory in an array, which works out, but when i look in the array all names of the directories and files are in small letters. What do I have to change, so that the names of files and dirs remain in their old notation ? also files like "Picture of Dog.jpg" are 3 entries in the array: Picture, of, Dog.jpg Is there a possibility to change that too ?

my code:

#!/bin/bash
currentDir="/home/marius/"
declare -l content=(` ls $currentDir `)
printf -- '%s ' "${content[@]}"
chepner
  • 497,756
  • 71
  • 530
  • 681
Marius Küpper
  • 257
  • 1
  • 4
  • 15
  • 1
    Once an question has been answered, don't edit it to ask a new question. Accept the given answer, and post a new question if necessary. anubhava's answer also solved your new question, by not using the output of `ls` to create the array. – chepner Nov 16 '14 at 17:38
  • Duplicate of [http://stackoverflow.com/questions/18884992/how-do-i-assign-ls-to-an-array-in-linux-bash](http://stackoverflow.com/questions/18884992/how-do-i-assign-ls-to-an-array-in-linux-bash) – Gordon Davisson Nov 16 '14 at 17:40

1 Answers1

3

You are using declare -l which by definition converts it to lowercase. As per help declare:

-l  to convert NAMEs to lower case on assignment

Just use this to create array without using ls:

declare -a content=("$currentDir"/*)
anubhava
  • 761,203
  • 64
  • 569
  • 643