Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I separate .sh files into a list?

I have tried:

ls *.sh  | xargs sed 's/\n/ /g' > out.txt

The return of ls *.sh is a long string with '\n' in the middle.

share|improve this question

You can try to use:

ls -1 *.sh
share|improve this answer

You don't want ls here: use ls when you want human eyes to see the nicely formatted output, not for when you want to parse filenames as data. Choose one of:

files=$(echo *.sh)

ary=( *.sh ); files="${ary[*]}'
share|improve this answer

I think:

ls *.sh | xargs

will give you want you want: a line with all the .sh files in the current folder.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.