Problem with the strlen function in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with the strlen function in ksh
# 1  
Old 07-24-2003
Problem with the strlen function in ksh

Hello,

Just a little problem with the ksh function : strlen

I want to use this function in this little ksh program :

while read line ; do
TOTO=$line
TOTONB=strlen($TOTO)
echo $TOTONB
# 2  
Old 07-24-2003
Problem with the strlen function in ksh

Hello,

Just a little problem with the ksh function in this program

while read line ; do
TOTO=$line
TOTONB=strlen ($TOTO)
echo $TOTONB
echo $line
done

So i have no value return in TOTONB , so i think that strlen don't work correctly . The doc don't give me any explications to avance in my problem.

I also test with the following lines :

TOTONB=$(strlen($TOTO)) --> don't work
TOTONB=strlen[$TOTO] --> don't work

Have anyone the good syntax or a explication for this problem

Thanks a lot...
# 3  
Old 07-24-2003
You have ksh mixed up with C or something. ksh has no strlen function. You can get the length of a string with:
string="something"
echo ${#string}
# 4  
Old 07-24-2003
strlen in ksh

Hello,

Your command is fun , it's run .

A have read a lot of documentation of the strlen function (all in C)and nowhere it's write that this function is not available in ksh.

Thanks a lot for your help...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KSH - different syntax for function

Hi, I wanted to know what's the difference between the below two syntax used for writing ksh function: e.g. 1 ------ function fn1 { echo "Hello World" } e.g. 2 ------ fn1 () { echo "Hello World" } (4 Replies)
Discussion started by: dips_ag
4 Replies

2. Programming

strlen for UTF-8

My OS (Debian) and gcc use the UTF-8 locale. This code says that the char size is 1 byte but the size of 'a' is really 4 bytes. int main(void) { setlocale(LC_ALL, "en_US.UTF-8"); printf("Char size: %i\nSize of char 'a': %i\nSize of Euro sign '€': %i\nLength of Euro sign: %i\n",... (8 Replies)
Discussion started by: cyler
8 Replies

3. Shell Programming and Scripting

Calling Function in KSH

I have a script with 2 functions 1) show_menu 2) create Ths show_menu function works fine....... Sort of.... When I select option 2 of the menu the code does a few commands and then calls another function called create. It's at this point that I get "create: not found"..... However,... (2 Replies)
Discussion started by: hxman
2 Replies

4. Shell Programming and Scripting

passing values to function in Ksh

Hi, I'm trying to work on the script given below #!/bin/ksh -x pfile() { echo "$1" } touch smp19 echo "Hi" > smp19 result=$(pfile $smp19) echo $result As highlighted , when i pass $smp19 as parameter ,it does not display the output.However when i try giving "Hi" instead... (2 Replies)
Discussion started by: Sheema
2 Replies

5. Shell Programming and Scripting

csh has function -x as ksh ?

Dear All, Normally, I use ksh to code script but I got a new assignment to check the error code of csh so I want to know csh has fuction -x(/bin/ksh -x) as ksh or not? If csh has, which mode? Another way, how can I check it my code is correctly? Thank in advance (2 Replies)
Discussion started by: unitipon
2 Replies

6. Programming

'strlen' of a constant string

In a declaration, I have: const char comment_begin = "<!--"; const char comment_end = "-->"; const int comment_begin_len = strlen(comment_begin); const int comment_end_len = strlen(comment_end); When I compile, I get the warnings: emhttpc.c:64: warning: initializer element is not... (10 Replies)
Discussion started by: cleopard
10 Replies

7. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

8. Shell Programming and Scripting

ksh: can you use getopts in a function?

I wrote a script that uses getopts and it works fine. However, I would like to put the function in that script in a startup file (.kshrc or .profile). I took the "main" portion of the script and made it a function in the startup script. I source the startup script but it doesn't seem to parse... (4 Replies)
Discussion started by: lyonsd
4 Replies

9. Shell Programming and Scripting

ksh built-in function

Does anyone know why the following expression return an error ] while the following one not ?? Thanks (1 Reply)
Discussion started by: solea
1 Replies

10. Programming

Problems with Strlen

hello, i have a problem with strlen. I have written this: for(y=13,z=0; cInBuf!=' ';y++) { cBuf=cInBuf; z++; } len = strlen(cBuf); out=len/2; fprintf(outfile,"F%i",out); If strlen is e.g. 22, it write F22. I want to write F2F2. How can i do this?... (5 Replies)
Discussion started by: ACeD
5 Replies
Login or Register to Ask a Question