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
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: