LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2007, 12:30 PM   #1
ramesh_manu
LQ Newbie
 
Registered: Dec 2006
Location: chennai, India
Distribution: redhat & mandriva
Posts: 17

Rep: Reputation: 0
string length


the second line of the following script finds the length of the string.


str="linux"
len=${#str}

But i want to know the exact meaning of the line. Because it is not a function. Moreover it retruns a string as result ( since $ prefix). How ?
 
Old 02-24-2007, 01:33 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Shell variables are always considered as string, unless they contain only digits and are used within an arithmetic comparison or operation. Indeed, they are generally un-typed. Nevertheless you can use the declare function in bash to assign a type. Regarding the length of the string, the statements below are equivalent:
Code:
${#string}
expr length $string
expr "$string" : '.*'
the last of them is the "classic" UNIX-style expr command to retrieve the length of $string. Bash introduced the ${#string} notation. You will find these explanations and a lot more on the Advanced Bash-Scripting Guide. A must reading!

Last edited by colucix; 02-24-2007 at 01:45 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Rewrite rule with query string in the pattern string basahkuyup Linux - Newbie 2 10-17-2006 03:06 AM
Trying to figure out the number of characters in a std::string, using length. RHLinuxGUY Programming 4 05-23-2006 10:39 AM
Limit a string length for translation? mic Programming 3 01-20-2006 07:58 PM
is there any limit for string length in basic_string? pippet Programming 13 02-01-2005 07:58 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 02:39 PM


All times are GMT -5. The time now is 10:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration