Linux shell command of a new method

1. After you define a function, use ". Xxx.sh" or "source xxx.sh" run the shell script in a shell script to establish their own, in which the function will automatically become the new in the current shell commands .

Will configure the environment 2. android runtime compiler build / envsetup.sh script, it is to use this approach to add some commands to the current shell, such as:. Croot, lunch, mm, mmm, mma, cgrep and so on. Envsetup.sh always thought what to do advanced operations was able to achieve such a magical effect, has also been sub-shell is how to change the directory parent shell worry, after reading the script and found that to achieve very simple and requires only the script a function can be defined, for example:

function croot()
{
    local T=$(gettop)
    if [ "$T" ]; then
        if [ "$1" ]; then
            \cd $(gettop)/$1
        else
            \cd $(gettop)
        fi
    else
        echo "Couldn't locate the top of the tree.  Try setting TOP."
    fi
}

End envsetup.sh this source can be used directly croot commands without any other operation.

 

3. Write a script to test

# cat cmd.sh

#! / bin / SH     # here dispensable 

function mycd () 
{ 
    CD / Home 
}

test:

@ Ubuntu root: / Home / Ubuntu / Android_work / Mytest # mycd         // to ensure the implementation of what the current shell is no such command 
root @ Ubuntu: / Home / Ubuntu / Android_work / Mytest # cmd.. SH   // need to run it this script, you can put it in ~ / .bashrc for each command line window automatically perform 
root @ Ubuntu: / Home / Ubuntu / Android_work / Mytest # mycd         // execute command 
root @ Ubuntu: / Home #                                          // cd / Home reflected in the shell of the parent.

 

 

 

 

reference:

In a new linux shell command easiest way

 

Guess you like

Origin www.cnblogs.com/hellokitty2/p/10962319.html