Find the answer to your Linux question:
Results 1 to 3 of 3
hi i m so new to linux like a baby ... need help how do i do this questions. Write a shell program called double66 that will prompt the user ...
  1. #1
    Banned
    Join Date
    Apr 2008
    Posts
    2

    need help basic scripts with arthmetic and others

    hi i m so new to linux like a baby ...

    need help how do i do this questions.

    Write a shell program called double66 that will prompt the user for a single integer and display twice its value.

    i used [raymond@localhost ~]$ expr 2 \* 2
    4
    my teacher say no way.

    also my other is

    (2)7. Write a shell program called home67 that prompts for any users login_id and returns the value of that users HOME directory. Recall that the Home directory is the sixth field in the /etc/passwd file.


    (3)8. Write a shell program called myecho68 that will do the following:

    a) print the number of arguments passed to it

    b) print the first three arguments on separate lines

    c) what argument list will produce the following output from this shell program?

    {Note this is only partial output from the script and may require mod to input data.
    Note do not redo script but determine what data would produce the following}

    Argument 1 is :I can not

    Argument 2 is :seem to

    Argument 3 is :find my Keys


    i dont know where to begin on this one.

    any help would be helpfull thanks

    airmax_sk@yahoo.com

  2. #2
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Hey There,

    I think you're doing the right thing (it's on valide way, anyway) with regards to your first assignment, you just need to put it in a script called double66, make that executable (I'm assuming "no" error checking... so a user could input a letter - just a rough idea):

    Code:
    #!/bin/bash
    
    echo "please enter an integer"
    read number
    newnumber=`expr $number \* 2`
    echo "You number doubled is $newnumber"
    You were just missing the wrapping

    You can use the same kind of user prompting to get your variable for the home67 script, and then use grep to find the line in /etc/passwd and awk to pick out the field.

    For your third assignment
    a) $# will return the number of arguments passed to your script
    b) use simple echo's for the variables (unless I'm misunderstanding)
    Code:
    echo $1
    echo $2
    echo $3
    c)I'm not sure what you mean here, but if your individual argument will have spaces in them, be sure to put them in double quotes on the command line when you execute your script.

    Hope that helps

    , Mike



    , Mike

  3. #3
    oz
    oz is offline
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,096
    Sorry, but it's against the forum rules to post homework questions:

    http://www.linuxforums.org/forum/lin...ums-rules.html
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...