directories=`ls`
However, this will create a variable containing each file separated by spaces like this:
adm agentx cache games lib lock log mail opt run spool tmp X11R6 ypTo place each item into its own element you simply need to add some brackets:
directories=(`ls`)
You can test this has worked with a simple loop:
directories=(`ls /var`)output:
for (( i=0; i<${#directories[@]}; i+=1 )); do echo ${directories[${i}]} ; done
adm
agentx
cache
games
lib
lock
log
opt
run
spool
tmp
X11R6
yp
No comments:
Post a comment