Execution problem with shell script

Hi all,
I want to use perl string manipulation commands in my shell script.
I have written following script.

 
echo "enter name"
read name
perl -e '$m=length($name);
echo $m

it gives an error: unrecognized token in perl command line.
do not suggest me an equivalent command of shell script.
just tell me what should i do to embed perl command in shell script?
thanks

Unnecessary to use an external program, use the shell built-in:

echo ${#name}

More generally, count any number of bytes from any source with "wc -c" (but for this it would count the line feed, too, so I echo without linefeed):

echo "$name\c" | wc -c | read name_len

That will not work for most people:

$ name=chris
$ echo "$name" | wc -c
6
$ echo "$name\c" | wc -c
8

Also, for most people, name_len will not contain the result you want. In most shells, all elements of a pipeline are executed in a subshell.
Use command substitution instead:

name_len=$( printf "%s" "$name" | wc -c )

Or better, as others have already pointed out, use the shell's own length expansion:

echo "${#name}"
1 Like