开发者

how to make a single shell-script to activate on multiple commands?

开发者 https://www.devze.com 2023-01-08 12:29 出处:网络
I would like to have one single file in my /bin which would \"listen\" to various commands, e.g. when I type into my console

I would like to have one single file in my /bin which would "listen" to various commands, e.g.

when I type into my console

ck sx

I would like script ck to do "sx" command, and when I type

ck st

I'd like it to do another thing, "st".

I bet it's easy to achieve I just don't know how exactly.

The idea is to have certain commands avaialbe from every location in my system. I want to control XAMPP behavio开发者_开发知识库r with very short commands so I don't have to click around all the time.

Is it something connected with one script with various parameters?

Or maybe I should just register given commands (or paths) to some "global commands" file?

I'm running Ubuntu 10.04.


$ cat ~/bin/multiscript
#!/bin/sh

do_sx () {
    echo "$@" 
}

do_st () {
    ls -lGi "$@"
}

case `basename $0` in
    sx) do_sx "$@" ; exit 0 ;;
    st) do_st "$@" ; exit 0 ;;
    *) echo "$0 command not defined" 1>&2; exit 1;;
esac
$ ln ~/bin/multiscript ~/bin/sx
$ ln ~/bin/sx ~/bin/st
$ chmod +x ~/bin/st
$ sx hi mom
hi mom
$ st ~/bin/sx ~/bin/multiscript ~/bin/st
 4932 -rwxr-xr-x 3 cyrylski 277 2010-07-19 20:17 /home/cyrylski/bin/multiscript
 4932 -rwxr-xr-x 3 cyrylski 277 2010-07-19 20:17 /home/cyrylski/bin/st
 4932 -rwxr-xr-x 3 cyrylski 277 2010-07-19 20:17 /home/cyrylski/bin/sx


You can use the $PATH variable to register the paths where you store your binaries. Try

echo $PATH

to guess the syntax, then do

export PATH=$PATH:/some/path/to/binaries
0

精彩评论

暂无评论...
验证码 换一张
取 消