Domanda

I want to list and store linux users into ruby array?

I have tried using system command

system "Cat /etc/passwd |grep '/home' |cut -d: -f1"

but it only returns true

How can I do it?

Thanks

È stato utile?

Soluzione

It's the expected behavior. From the documentation:

system returns true if the command gives zero exit status, false for non zero exit status.

Use Kernel#` (backticks) instead:

output = `cat /etc/passwd |grep '/home' |cut -d: -f1`

String#lines converts this into an array of lines.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top