Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Using the sort command with an if/then statement


    Well, I figured out the other part, now I need to get this part of my homework done.

    So part of my assignment is to make a simple code where I enter four names as a command line parameter. After the names are displayed, then the program must sort the output so if I enter:

    Barry
    David
    Carl
    Alex

    It will show the names and then sort the output to show

    Alex
    Barry
    Carl
    David

    The only thing is, I can't get it to sort, I keep getting this error: "sort: open failed: +m: No such file or directory"

    Once again, let me know what I did wrong. Here is my code...

    #!/bin/bash

    if [ $# = 4 ]
    then

    echo You have entered these four names
    echo $1
    echo $2
    echo $3
    echo $4
    else
    echo You must enter four names only
    fi

    sort $ phantom

    Thanks for your help and your patience...

    -MP-

  2. #2
    hi,

    `sort' sorts files or data from a pipe.

    you should use `printf '%s\n' "$@"`

  3. #3

    still not working...

    I should probably mention that I'm on Ubuntu

    I tried to use what you posted and it gave me a "command not found" error.

    Or the better question is, what did I do wrong?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    848
    Hi Outsider

    I'm afraid homework questions are against the rules.

    http://www.linuxforums.org/forum/lin...ums-rules.html
    Linux User #453176

  6. #5
    My mistake...sorry about that...

  7. #6
    Kieren, this rule is agianst people posting their assignment without code.
    here, Outsider418 posted his attempts.
    so, IMO there is no problem.

    Outsider418,
    what did I do wrong?
    what did you do?
    are you sure you're using bash?
    how do you execute your script?

Posting Permissions

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