Find the answer to your Linux question:
Results 1 to 5 of 5
I have a looping case menu system, w/ a command to call an outside command if necessary, but it will not let me pass multi-word commands, like this: while true; ...
  1. #1
    Just Joined!
    Join Date
    Nov 2006
    Posts
    90

    passing commands out of case

    I have a looping case menu system, w/ a command to call an outside command if necessary, but it will not let me pass multi-word commands, like this:

    while true; do
    "x" ) #use external command
    echo -n "Your Bidding my Leige? "
    read command
    command "$command"
    read -n 1 foo
    ;;
    esac
    done

    i can use single word commands like ls, but not say, ls /mnt/sda1/ or it will spit out invalid command/file. can this be solved? ( i have also tried this w/o command before "$command", but same result)

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Hm, sure you should be able to do this, and it shouldn't be difficult either. Four things come to mind from your example.
    First, you give two 'read' commands,but the second one isn't useful.
    Second, the 'ls /mnt' example you give, I don't know if this is the real purpose of your command, but 'ls' as the second command in a string isn't really working. I mean, it could do something useful in some occasions, but generally 'ls' goes first...
    Thirth, there is no pipe or redirection in your example. Use one of |, <, >, >>
    And fourth, You don't want to use the double quotes around the $command. Many commands will not see "$command" as a variable, but as a literal string.

    If you'd do this:
    Code:
    while true; do
    "x" ) #use external command
    echo -n "Your Bidding my Leige? "
    read -n 1 command #grep testword -or- cut -d, -f4- -or- anything else should work
    command | $command
    ;;
    esac
    done
    It helps if you know beforehand how you want the command to look like without variables. You could, for example, want command | $command to end up doing:

    Code:
    cat tempfile | cut -d, -f2 | grep -i --color=always testword | uniq
    And you should be able to do so with the above example.

  3. #3
    Just Joined!
    Join Date
    Nov 2006
    Posts
    90
    it belongs in a virus scanner for my computer shop that i designed. the menu is to make it easy on our windows friends so they do not need to know linux commands, but i don't like not having an output. read -n 1 foo causes the machine to pause before continuing similar to dos pause. what does the read -n 1 ... line mean in your reply? i dont understand the code. (newbie i am) ls was not supposed to go second, my mistake. (seeing how many mistakes i made in this one little chunk of code, id hate to see your reaction to my whole 7.6k script. you would probably take be before the "linux counsel of elders" and have Torvalds ban me from scripting forever. lol)

  4. #4
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    t belongs in a virus scanner for my computer shop that i designed. the menu is to make it easy on our windows friends so they do not need to know linux commands,
    If they knew Linux commands, you wouldn't need a virusscanner
    Just kidding...

    what does the read -n 1 ... line mean in your reply?
    It's simply a way to tell the system to accept only one single keystroke as input.

    ls was not supposed to go second, my mistake. (seeing how many mistakes i made in this one little chunk of code, id hate to see your reaction to my whole 7.6k script. you would probably take be before the "linux counsel of elders" and have Torvalds ban me from scripting forever. lol)
    This was just a test, the Linux Counsel of Elders wants you to continue. They said: "Praise is upon you, who eases the life of Windows users"

    I understand you where just giving an example, but since I could not see from your example where the fault was, I commented on every little thing I could find As n00bs amongst each other, I felt it might help. Dunno if I did though, is it working now?

  5. #5
    Just Joined!
    Join Date
    Nov 2006
    Posts
    90
    it works great. thanks for the advice. it is almost out of beta. it should be ready for all my windows friends by next week.

Posting Permissions

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