Find the answer to your Linux question:
Results 1 to 2 of 2
Ok so im working on a script that will allow the user to input the name of a file..I want to except bascially anyfile..whether it has an extention or not, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2004
    Location
    usa
    Posts
    7

    Need Help..Bash Script..Allowing Certain Input..


    Ok so im working on a script that will allow the user to input the name of a file..I want to except bascially anyfile..whether it has an extention or not, starts with a number or letter..For some reason, this doesnt seem to be working..

    -- Start of Function --
    sort() {
    echo -n "Please Type the File Name to Sort.. "
    read sort1

    while [ ${sort1} == "[^a-z]" -o ${sort1} == "[^0-9]" \
    -o ${sort1} == "[^0-9]*" -o ${sort1} == "[^0-9].*" ]
    do
    echo "Invalid response. Please Give File Name, and File Extension if
    Applicable."
    echo -n "Please Type the File Name to Sort.. "
    read sort1
    done

    Does anyone have any suggestions? What would be an easier way to make it so it will accept any file, or what am i doing wrong here? Thanks in Advance!

  2. #2
    Just Joined!
    Join Date
    Feb 2004
    Posts
    23
    why don't you ise the programm: sort ?
    it pretty standard on most linux distro's

    but if you are determined to write a script that does it

    You are using while and while uses white space characters as a seperatorso when you enter a filename with a white space character in it while sees 2 entrys in stead of 1

    you could escape these entrys with \
    this is a filename with whitespace characters.extension
    should be entered as:
    this\ is\ a\ filename\ with\ whitespace\ characters

    this also goes for the wildcars like * and ? and . (yes "." is a wildcard in a regular expression)
    and for things like " ' ` ~ !

    hope this helps a bit

Posting Permissions

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