Find the answer to your Linux question:
Results 1 to 9 of 9
i'm supposed to code a linux shell script named fileinof which allows users to view info on files in a specified directory and the script will accept one optional parameter ...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Posts
    5

    bash scripting newbie can someone tell me what i'm doing wrong?

    i'm supposed to code a linux shell script named fileinof which allows users to view info on files in a specified directory and the script will accept one optional parameter as a directory path.

    here's what i got so far

    $ cat fileinfo
    #!/bin/s

    if [ $# -ne 1 ]; then
    echo 1>&2 Usage: fileinfo [directory path]
    exit 127
    fi


    but at the command line when i enter $ ./fileinfo it says bash: $: command not found. WHY? am i missing something? i can't figure it out.

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Could be the 1st line:

    #!/bin/s

    Should be:

    #!/bin/bash

  3. #3
    Just Joined!
    Join Date
    Nov 2007
    Posts
    5
    I fixed that problem, but it still gives me the same error:

    bash: $: command not found

  4. #4
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    You are typing $ then the command. You need not type the $.

  5. #5
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    How are you trying to run the script. It should be:

    ./fileinfo

    Also you need quotes around the error message:

    echo 1>&2 'Usage: fileinfo [directory path]'

  6. #6
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Make the file executable with the chmod command.

    Regards

  7. #7
    Just Joined!
    Join Date
    Nov 2007
    Posts
    5
    thank you! i feel like such an idiot.

    how would i process the files in the directory that was entered?

  8. #8
    Just Joined!
    Join Date
    Nov 2007
    Posts
    5
    or i mean how would i check if that directory existed?

  9. #9
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    You can do that with the test command.
    I highly recommend you to read something about shell scripting. Go here for the tutorials:

    Linux Shell Scripting Tutorial - A Beginner's handbook
    http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
    http://tldp.org/LDP/abs/html/


    Regards

Posting Permissions

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