[Bash] array `ls` output
I'm having a problem with arraying the output of the list function, ls, which is strange because I just had the capability earlier today.
bash-3.2$ array=$(`ls`) bash: asat: command not found I simply want to create an array that has file listings from the current directory. Any suggestions? Thanks. |
You mean 'array=($(theCommandToRun))'? BTW watch your IFS if you do stuff like that.
|
Correct. None of the file listings currently have white spaces, so I don't think I'm having a problem related to IFS. I thought I was performing a pretty basic operation, and it was working until about an hour ago.
|
Quote:
|
I don't know why it worked for you before. Doesn't seem like it should have. But you can accomplish what you want using:
Code:
array=($(ls)) Code:
array=(`ls`) |
ls may be aliased. It often is. To be sure of getting the standard command use /bin/ls or \ls.
ls lists files across the page. To get one per line use ls -1 (that's a number 1). The robust way to read file names into shell variables is detailed here as Code:
find . -type f -print0 | while IFS= read -r -d '' filename; do |
All times are GMT -5. The time now is 04:15 PM. |