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"?

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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