Custom Bash functions & custom statements - Need some advice

56 Views Asked by At

My question is a bit complex, but I'll try to make it clear. I want to create a Bash function. Now, here's the interesting part - I want to do this by referencing what the user will type.

Since I don't know what that is, I'll optionally refer to it as $2, $3. How can I make it so that I can extract the commands that the user will type?

For example

function check() {
    case $1 in
    -c)
    if [ -x $2 || -x ${@} ]
        then
    ${@} $* # these ("$@ & $*) represent what goes into this function
    fi
    esac
}

Then I call the function - "check -c /usr/".

Working with the func, for example:

if [ check -c | grep "/usr" != 0 ] # "check -c" is my func

then

cd /usr/

fi

Or: check -c /usr/ && ls *

If it succeeds, how do I continue writing what I want to do after "check -c /usr/"? Right after? Or in a new line?

It's a bit like making a programming language - how do I make it so that these commands I type into the functions run? In short - I would like to create such functions for programming myself. Or should such things be done in C? If so, can I get links to study it? The point of this is to make programming easier for myself.

I hope that was clear. If not, I can't explain it any better than that. Thanks in advance for your help!!!!

I just tested this, but not with much success.

0

There are 0 best solutions below