shell script execution error in uclinux
I have a simple shell script as follows:
myfunc()
{
#print hello world
echo "Hello World";
}
myfunc
The script works fine when I execute in linux pc but when I run the same in uclinux, I get the error as "syntax error". What could be reason for the problem?
Update:
The following code works in uclinux:
####\#!/bin/sh
echo "Hello World"
But, the following code is not working:
####!/bin/sh
myfunc()
{
#p开发者_如何学编程rint hello world
echo "Hello World";
}
myfunc
The result depends what shell you run. Most uclinux's shells are actually symbolic links to Busybox. Busybox implements various tiny shells for different memory foot print requirements. As I remember, only ash supports function syntax. Check your busybox version and its build config.
Maybe your installation of uclinux uses a different shell?
Saying "shell script doesn't work" is like saying "my source code doesn't work". Of course the phrase only makes sense if you say what language your source code is in. Similarly for shell script: is it bash? is it ksh? is it tcsh? For uclinux I highly suspect it's busybox.
Your shell script should have a shebang line that will cause the script to be executed by the shell you designate. This can reduce or eliminate many unexpected errors due to differences in syntax between shells that are caused when the script is executed by the current (or default) shell which may be different for a number of reasons.
The first line of the script file should be similar to:
#!/bin/sh
with the path and name of the shell appropriate to your needs.
Is your actual myfunc
defined in one line as you show it? That's a syntax error since you're commenting out lots of stuff including the }
.
If you put myfunc() { #print hello world echo "Hello World"; }
on one line, then
#print hello world echo "Hello World"; }
gets interpreted as comment. Remove the part #print hello world
and try again.
if using Busybox and hush
Configure Your BusyBox Shell Part To suppot Function:
make busyBox-menuconfig
Shells -> Support Function .... (Should be checked )
精彩评论