0

I'm a new user on Ubuntu and working on a task, but I haven't found any way to resolve this problem. Here is the statement:

finger takes the user account name as the argument. You can feed the user name to finger using the whoami command and piping the output to xargs. The argument for xargs is, of course, the finger command.

I have done all the work and I know how to use the finger command but whenever I use find . file.sh | xargs finger {username} I don't get the required result. Basically i want to run the one file .sh and then after .sh file the finger command should be run automatically. As like this screenshot enter image description here

Here is my code you can see this

#!/bin/bash

echo -n "What is your name? ";
read  name;

echo -n "Are you a (S)tudent or a (P)rofessor? ";
read  s_or_p

if [ $s_or_p = "P" -o $s_or_p = "p" ]; then

    student_or_professor="professor"
    research_or_scholastic="research"

    echo -n "Where do you work? ";
    read  workplace_or_college

    echo  "What are your top 3 research interests? ";
    read  interest1
    read  interest2
    read  interest3

    echo  "$name is a $student_or_professor that works at $workplace_or_college." >> ~/.plan


else 
    if [ $s_or_p = "S" -o $s_or_p = "s" ]; then
    student_or_professor="student"
    research_or_scholastic="scholastic"

    echo -n "Where do you attend? ";
    read  worksat_or_attends

    echo  "What are your top 3 scholastic interests? ";
    read  interest1
    read  interest2
    read  interest3
    echo  "$name is a $student_or_professor that attends $worksat_or_attends." >> ~/.plan

    fi
fi

echo "$name's $research_or_scholastic interests include:" >> ~/.plan;
echo  $interest1 >> ~/.plan
echo  $interest2 >> ~/.plan
echo  $interest3 >> ~/.plan

echo "Running finger on your account..."
find . planner.sh | xargs finger linux

closed as unclear what you're asking by jasonwryan, roaima, Ramesh, muru, vonbrand Nov 11 '15 at 1:41

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • i have completed the both tasks separately but i don't know how to run both from a single file and how to pass the output of .sh file to xargs command please help me .. – Error3735 Nov 10 '15 at 21:52
1

Your requirements state,

You can feed the user name to finger using the whoami command and piping the output to xargs. The argument for xargs is, of course, the finger command.

You then yourself say that you use this command: find . file.sh | xargs finger {username} but that you don't get the required result.

The command you have designed doesn't match the criteria given in the requirement. Let's break that down:

The argument for xargs is [...] the finger command

OK, so we have xargs finger. This requires input, and each line of input is appended to the end of the finger command by xargs.

feed the user name to finger using the whoami command

We can't do whoami | finger (well we can, but it's meaningless as finger doesn't read from stdin), but we can apply the output of whoami to the end of the finger command like this:

whoami | xargs finger

That should answer the first part of your question. When you've used this and worked out what's missing in your second part perhaps you'd like to update your question with the new information.

  • i have completed the both tasks separately but i don't know how to run both from a single file and how to pass the output of .sh file to xargs command please help me. I have made .sh file which will take the user data as like in the screen shot then after completing the user's input i want to give that output to the .paln file through xargs command and whenever i'll run the .sh file the .plan file should be run too. – Error3735 Nov 11 '15 at 11:15
  • @Error3735 you don't "run" a .plan file - it's just text. Please update your question to explain properly what you are trying to achieve. Questions to consider: 1. if you're trying to run two commands in a script why can't you just put them on consecutive lines? 2. Why do you want to send the user's input through xargs? 3. What do you really mean by "running" the .plan file? – roaima Nov 11 '15 at 11:40
  • it's given in the description and the .pan file is a file when we run a command in a shell finger [username] then it shows all data of the login user and in the last it shows the mail and plan of the user. Basically i want to update that plan. – Error3735 Nov 11 '15 at 13:33
  • Please check my code's last lines i have uploaded above with the screenshot.I want same out put after running my script file, i have a planner.sh file in which i'll ask questions to the user and then pass that output to variables to the .plan file like echo $interest1 >> ~/.plan so that when i'll run my file planner.sh that will show the updated plan of the finger command.. – Error3735 Nov 11 '15 at 13:47
  • @Error3735 you want to run the script called planner.sh? – roaima Nov 11 '15 at 14:33

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