- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to capture a string of characters with ksh
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
04-28-2003 11:07 AM
04-28-2003 11:07 AM
Something like:
echo "Type your notes:\n"
CAPTURE NOTES
There will be 60 characters or less typed by the user.
I am attempting to use the string of characters to be inserted into a table afterwards by using PL/SQL.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 11:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 11:12 AM
04-28-2003 11:12 AM
Re: how to capture a string of characters with ksh
# echo "Enter your message"
# read MSG
# echo "You wrote: '${MSG}'"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 11:17 AM
04-28-2003 11:17 AM
Re: how to capture a string of characters with ksh
I am going to double check all my steps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 11:18 AM
04-28-2003 11:18 AM
Re: how to capture a string of characters with ksh
read
just by itself will put the input in to the default variable REPLY
read varName
will put the input into the variable varName
a trailing \ at the end a line causes the line to be continued onto the next line. ksh will remove both the \ and newline.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 11:19 AM
04-28-2003 11:19 AM
Re: how to capture a string of characters with ksh
The previous suggestions were great, but you might want to add a typeset declaration of your variable so that it will be limited to a certain size. Using JRF's example,
typeset -L60 ans
will limit the ans variable to 60 characters, left justified, with leading blanks removed and trailing blanks added to make it 60 characters.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 11:58 AM
04-28-2003 11:58 AM
Re: how to capture a string of characters with ksh
In the shell script:
============================
echo "Please include your comments below (60 char max):\n"
read NOTES
sqlplus -s $LOGIN @zipadd_tst.pl $ZIP $SERVICE $BRANCH $USER '${NO
TES}'
============================
At the read, the user inputs something like "This is a test"
But when reviewing the table, the only value recorded is "This"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 12:10 PM
04-28-2003 12:10 PM
Re: how to capture a string of characters with ksh
Surround your variable with double-quotes:
# ... "${NOTES}"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 12:11 PM
04-28-2003 12:11 PM
Re: how to capture a string of characters with ksh
Your sqlplus statement is seeing the $NOTES variable as more parameters and it just getting the first value. Try quoting the $NOTES variable like this:
sqlplus -s $LOGIN @zipadd_tst.pl $ZIP $SERVICE $BRANCH $USER \"${NOTES}\"
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2003 12:25 PM
04-28-2003 12:25 PM
Re: how to capture a string of characters with ksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2003 09:40 AM
04-29-2003 09:40 AM
Re: how to capture a string of characters with ksh
My main problem is resolved, how can I make typeset not leave any trailing spaces, I don't care for additional dead space. I only want recorded what is typed, nothing else, even if I limit it to 60 characters.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2003 09:44 AM
04-29-2003 09:44 AM
Re: how to capture a string of characters with ksh
How about if you use sed to remove any leading and trailing white space
sed 's/^[ \t]*//;s/[ \t]*$//'
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2003 09:59 AM
04-29-2003 09:59 AM
Re: how to capture a string of characters with ksh
As of right now, I have not set limitis to the lenght of the string, so whatever characteres are typed, that's the only thing that is loaded (typeset is not used), just what I want, but as John has said, the user may type beyond the screen's width (not really recommended) and other limitations. But if I was to set limits with typeset (60 characters is practical, furthermore is the lenght of the field, a varchar2(60)), I don't want trailing spaces, I still only want what is typed to be loaded on the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2003 10:03 AM
04-29-2003 10:03 AM
Re: how to capture a string of characters with ksh
The typeset functions in ksh [and posix sh] pad the field with trailing spaces. There isn't any option for typeset to tell it to strip out the spaces or not pad the field.
You could use Sachin's suggestion with sed to strip off the trailing spaces. The Korn shell is nice, but the deeper you get into trying to solve problems like this, the closer you get to needing Perl.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2003 10:09 AM
04-29-2003 10:09 AM
Re: how to capture a string of characters with ksh
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2003 11:16 AM
04-29-2003 11:16 AM
Re: how to capture a string of characters with ksh
It is very simple
#!/bin/sh
typeset -L10 ans
read ans
echo "TTT${ans}TTT"
ans2=`echo ${ans} | sed 's/^[ \t]*//;s/[ \t]*$//'`
echo "TTT${ans2}TTT"
And when I run this script
hpc-ps3# ./ttt
12345678
TTT12345678 TTT (output without truncat)
TTT12345678TTT (after using sed)
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2003 01:12 AM
05-02-2003 01:12 AM