Need some help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need some help
# 1  
Old 02-04-2015
Need some help

Hi guys. I would need some help really fast..

I have to show a user as a parameter and its group. If the user doesn't exist the script will show "user doesn't exist".
How could I do that?
UNIX
# 2  
Old 02-04-2015
Is this homework?
# 3  
Old 02-04-2015
this is exam
# 4  
Old 02-04-2015
Quote:
Originally Posted by rbatte1
Is this homework?
It probably is homework. Here is a Bash one liner that should work:

Code:
echo "enter a username to search for:" ; read username ; if [ `grep -ic "^${username}" /etc/passwd` -gt 0 ]; then grep -i "^${username}" /etc/passwd | cut -d":" -f1,4 | tr [:] [\ ] ; else echo "user doesn't exist"; fi

Now all that the OP needs to do, is figure out what I did and how it works... Smilie

Last edited by gandolf989; 02-04-2015 at 12:13 PM..
This User Gave Thanks to gandolf989 For This Post:
# 5  
Old 02-04-2015
Quote:
Originally Posted by gandolf989
It probably is homework. Here is a Bash one liner that should work:
Gandolf989, as much as i appreciate your contribution, but:

Moderator's Comments:
Mod Comment there are rules in place and they are there for a reason. I, for one, wouldn't like to have a colleague who - instead of knowing his stuff at the exam - passed it only because of someone knowledgeable fed him his lines. In fact i once had such a colleague and i didn't like doing the work of two alone very much. I assume you wouldn't like to be treated by a physician who needed help to pass his exams, no?

Therefore, please, if someone asks if a certain question is homework, especially if it someone from the moderation team: wait until an answer is given.

For a long time we didn't allow any coursework/homework-related questions at all. At one time and after giving all the pros and cons a lot of considerations we consulted a specialist in this area (a university professor dealing with such issues) and we recognized that there are sometimes classes where the students are not given the necessary information to do their studying.

We created a special forum for homework/coursework questions where we try to answer questions of students in a way so that they are able to work their way to an answer themselves. There needs to be the class and the name of the teacher revealed so that the student has to acknowledge what help he relied on and in which way it was given. We allow students questions only in these special board and only after a proper identification of the course/class is given.


Furthermore, there might be a problem with your code: consider there would be a user "xyz" and you search for user "xy". How would your script react, hm?

bakunin
# 6  
Old 02-04-2015
I think it would always only report user oracle too.

Maybe you left these nuggets in for the requester to debug and therefore learn ...? Smilie
# 7  
Old 02-04-2015
Quote:
Originally Posted by rbatte1
I think it would always only report user oracle too.

Maybe you left these nuggets in for the requester to debug and therefore learn ...? Smilie
No, I just tested it with the Oracle user and did not change both places where I had it hard coded. Smilie

---------- Post updated at 11:18 AM ---------- Previous update was at 11:14 AM ----------

Quote:
Originally Posted by bakunin
Gandolf989, as much as i appreciate your contribution, but:

Moderator's Comments:
Mod Comment there are rules in place and they are there for a reason. I, for one, wouldn't like to have a colleague who - instead of knowing his stuff at the exam - passed it only because of someone knowledgeable fed him his lines. In fact i once had such a colleague and i didn't like doing the work of two alone very much. I assume you wouldn't like to be treated by a physician who needed help to pass his exams, no?

Therefore, please, if someone asks if a certain question is homework, especially if it someone from the moderation team: wait until an answer is given.

For a long time we didn't allow any coursework/homework-related questions at all. At one time and after giving all the pros and cons a lot of considerations we consulted a specialist in this area (a university professor dealing with such issues) and we recognized that there are sometimes classes where the students are not given the necessary information to do their studying.

We created a special forum for homework/coursework questions where we try to answer questions of students in a way so that they are able to work their way to an answer themselves. There needs to be the class and the name of the teacher revealed so that the student has to acknowledge what help he relied on and in which way it was given. We allow students questions only in these special board and only after a proper identification of the course/class is given.


Furthermore, there might be a problem with your code: consider there would be a user "xyz" and you search for user "xy". How would your script react, hm?

bakunin
That is a valid point. But if the goal is to educate, the one liner showed that you can string together a number of statements and get the answer. Ideally people learn through careful study and practice, but for most people I think they need to see a code example. So my code, although it was initially wrong, demonstrated how to break the problem down into smaller problems that can easily get solved.

Of course if he is really taking a test, he probably did not get what he wanted in time to cheat. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question