Reputation: 21
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?
The following code works in uclinux:
####\#!/bin/sh
echo "Hello World"
But, the following code is not working:
####!/bin/sh
myfunc()
{
#print hello world
echo "Hello World";
}
myfunc
Upvotes: 1
Views: 712
Reputation: 1
if using Busybox and hush
Configure Your BusyBox Shell Part To suppot Function:
make busyBox-menuconfig
Shells -> Support Function .... (Should be checked )
Upvotes: 0
Reputation: 2047
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.
Upvotes: 1
Reputation: 409
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.
Upvotes: 0
Reputation: 677
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 }
.
Upvotes: 0
Reputation: 360665
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.
Upvotes: 0
Reputation: 114014
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.
Upvotes: 0