user379203
user379203

Reputation: 95

How can I access the output of ls in bash?

I write the following script, expecting to print files in a directory. But it is just throwing the string "ls" on to screen.

What is the problem?

#!/bin/bash
for FILE in 'ls' 
do
   echo $FILE
done

Upvotes: 0

Views: 461

Answers (1)

user2100815
user2100815

Reputation:

Wrong kind of quotes - you want:

for FILE in `ls`

Those are the backticks, not the single-quotes. Better still:

for FILE in $( ls )

You might also want to look at this site.

Upvotes: 9

Related Questions