- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script Question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:32 AM
05-01-2002 06:32 AM
Script Question
find the length of a string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:34 AM
05-01-2002 06:34 AM
Re: Script Question
x="abcdef"
echo ${#x}
6
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:34 AM
05-01-2002 06:34 AM
Re: Script Question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:34 AM
05-01-2002 06:34 AM
Re: Script Question
#man wc
wc recognizes the following command-line options:
-c Write to the standard output the number of bytes in
each input file.
-m Write to the standard output the number of characters
in each input file.
-w Write to the standard output the number of words in
each input file.
-l Write to the standard output the number of newline
characters in each input file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:35 AM
05-01-2002 06:35 AM
Re: Script Question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:37 AM
05-01-2002 06:37 AM
Re: Script Question
Then minus 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:39 AM
05-01-2002 06:39 AM
Re: Script Question
What about wc -c , where in it counts the no. of bytes in the input .
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:43 AM
05-01-2002 06:43 AM
Re: Script Question
S1="This is a test"
LEN=`expr length "${S1}"`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:46 AM
05-01-2002 06:46 AM
Re: Script Question
Rodneys method works fine if you mean to use the posix shell (/usr/bin/sh on HP-UX). The *real* bourne shell on HP-UX is in /usr/old/bin/sh. Posix shells aren't available on all flavours of UNIX so if you *really* want to use the bourne shell then the methods using wc will work fine - but remember that wc will include the new line from the echo command in the output so you will always get the length of your string plus one unless you tell echo not to include the newline:
# /usr/old/bin/sh
# x="1234"
# echo ${#x}
bad substitution
# exit
# x="1234"
# echo ${#x}
4
# echo $x | wc -m
5
# echo "$x\c" | wc -m
4
HTH
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:49 AM
05-01-2002 06:49 AM
Re: Script Question
I bad.
I started /usr/bin/sh and forgot it was posix.
Good call Duncan...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:50 AM
05-01-2002 06:50 AM
Re: Script Question
$YOUR_STRING=1234567
$STRING_NUM=`echo "$YOUR_STRING\c" | wc -c`
#echo $STRING_NUM
7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:50 AM
05-01-2002 06:50 AM
Re: Script Question
((a=a-1))
echo $a
5
Regards,
Dave.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 06:54 AM
05-01-2002 06:54 AM
Re: Script Question
Bear in mind however that it is not valid in the real Bourne shell (/usr/old/bin/sh). You're not using that are you?
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 07:00 AM
05-01-2002 07:00 AM
Re: Script Question
Try this:
$ DAH1="this is a test"
$ echo $DAH1
this is a test
$ echo ${#DAH1}
14
$
If it works you are really using the posix shell. The bourne shell in 10+ is in /usr/old/bin. The bourne shell still exists for older scripts, and should be "ported" to the posix shell.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2002 07:24 AM
05-01-2002 07:24 AM
Re: Script Question
# var=0123456789
# echo ${#var}
10
Magdi