rachuism rachuism - 4 months ago 8
Linux Question

Why do I obtain blank response when listing linux users?

I'm trying to list all the users of my system with "cut" approach but I obtain nothing, any idea?

#!/bin/bash

cat /etc/passwd | cut -d":" -f 1 > user

echo $user

Answer

As it's already mentioned in the comment above the problem is that you redirect your output to the file named user.

So, possible solutions are:

1) Check the user file's content.

2) Adjust your command to write it's output to the user variable:

user=`cat /etc/passwd | cut -d":" -f 1`
echo $user