开发者

calling function from command line

I have written a function that is working as expected within the shell script. But how do I call it from command prompt? I tried the alias command, but I get an error

bash: syntax error near unexpected token `)'

There is no such error when I type sh myscript.sh at command prompt.

Here is the new error:

# alias start_multi="start_multi () (for socket in {2..9} do; /usr/bin/mysqld_multi start $socket; done )"

# start_multi
bash: syntax error开发者_运维百科 near unexpected token `/usr/bin/mysqld_multi'


The alias you're trying to create will not do what you expect, aside from having a syntax error (using parentheses instead of braces). For example:

alias foo='bar() { echo Hello; }'

Will create an alias foo, that when executed, will define the function bar. So:

# foo
# bar
Hello

You either want to skip the function declaration in the alias (making it just the for loop), or create a text file with the function declaration and source it (. myscript.sh).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜