1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #!/bin/bash # Write a shell program to concatenate to two String given as input and display the # resultant string along with its string length. # -------------------------------------------------------------------- # This is a free shell script under GNU GPL version 2.0 or above # Copyright (C) 2005 nixCraft project. # Feedback/comment/suggestions : http://cyberciti.biz/fb/ # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- STR1=$1 STR1=$2 OUT="$1$2" if [ $# -eq 0 ] then echo "$0 string1 string2" exit 1 fi len=$(expr length $OUT) echo "Concatenate string is - $OUT" echo "String Length is - $len" |
get rid of the ` in your expr
for instance, if you wanted to get the length of s3 in len, you;d do
len= expr length $s3
echo $len
HTH
..
Why doesn’t this work?????
#!/bin/sh
echo “Enter first string:”
read s1
echo “Enter second string:”
read s2
s3=$s1$s2
len=
echo $s3 | wc -c
len=
expr $len - 1
echo “Concatenated string is $s3 of length $len “
concatenation is performed
but
length doesn’t calculated
to get the length of a string can I use len=
echo $str | wc -c
?????what is length in the expression “len=$(expr length $OUT)”
did you write that function or SHELL has that function?