0

I am a beginner in Ubuntu bash and couldn´t find a solution after searching for hours.

I have a config file with lines like:

u:TestUser:rw:/home/temp/testFolder

I want to give the user the rights to this folder, but first I have to check if the user exists and if not, create that user.

The only problem I have is extracting "TestUser" from between the colons. With that I could check if the user exists with /etc/passwd.

d0neall
  • 81
  • 7

1 Answers1

0

You need to "cut" the text between delimiters. A job for cut:

cut -d: -f2 /etc/passwd
  • -d: - set's the delimeter to : (default is tab)
  • -f2 - will make cut print only the second field frim the file - ie. username

But to check if a user exists on a system, see superuser - Find out if user name exists and use id command.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111