0

Say we are using ubuntu's bash and we cd to the folder myFolder.

Now, say we use ls in this folder, and we get a list of files:

file1 file2 file3

We want to, for the sake of this example, run file2 on node.

Is there a way to choose the file based on it's position on the ls list/ folder? For example, something like node "secondFileOfFolderHere"?

1 Answer 1

0
node "$(ls -1 | awk 'NR==2')"

-1 switch lists one file per line; awk prints line 2

2
  • what does nr stands for?
    – badso
    Nov 1, 2015 at 19:08
  • Current record (i.e. line) number
    – SΛLVΘ
    Nov 1, 2015 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .