- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- /usr/bin/tr -cd [0-9] is not working for some use...
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
01-19-2009 06:41 PM
01-19-2009 06:41 PM
here is the script...
---------
#!/bin/ksh
#=====================================================================
# Name: Alc_payroll_option1.sh
#
# Description: This process is called when option 1 from
# the payroll menu is chosen
SMTLOC=`echo $SMTLOC`
LOCNAM=`echo $LOCNAM`
export UEC
sdate=`date +"%D %T"`
user=`whoami`
trap 'read pause"Control-C will not terminate menu press enter to Return."' INT
trap 'read pause"Control-/ will not terminate menu press enter to Return."' QUIT
trap 'read pause"Control-Z will not terminate menu press enter to Return."' TSTP
clear
echo "Are You Sure You Want To Start The Payrules Processing? (Y/N) \c"
read ok
if [ $ok = 'Y' -o $ok = 'y' ]; then
echo " Payrules Processing for : $SMTLOC - $LOCNAM\nEnter Week: \c"
read week
week_numeric=`echo $week | tr -cd [0-9]`
echo "You Entered Week Number $week_numeric is that correct? (Y/N) \c"
----------
If i enter week=4 then i expect week_numeric=4 . But week_numeric is returning blank.
Also tried manually for that user outside the script like this
[kumarts@/home/kumarts] #echo $week_numeric
ksh: week_numeric: parameter not set
[kumarts@/home/kumarts] #week=4
[kumarts@/home/kumarts] #week_numeric=`echo $week | tr -cd [0-9]`
[kumarts@/home/kumarts] #echo $week_numeric
[kumarts@/home/kumarts] #
also tried week_numeric=`echo $week | /usr/bin/tr -cd [0-9]`
this is impacting only some set of users.All the users have the /usr/bin/ksh defined.
Any one has Suggestions??
Solved! Go to Solution.
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2009 07:23 PM
01-19-2009 07:23 PM
Re: /usr/bin/tr -cd [0-9] is not working for some users
a) Firstly, your Ksh script is not valid.
It is missing the "fi" to end the loop.
This is what you have:
if [ $ok = 'Y' -o $ok = 'y' ]; then
echo " Payrules Processing for : $SMTLOC - $LOCNAM\nEnter Week: \c"
read week
week_numeric=`echo $week | tr -cd [0-9]`
echo "You Entered Week Number $week_numeric is that correct? (Y/N) \c"
This is what you SHOULD have:
if [ $ok = 'Y' -o $ok = 'y' ]; then
echo " Payrules Processing for : $SMTLOC - $LOCNAM\nEnter Week: \c"
read week
week_numeric=`echo $week | tr -cd [0-9]`
echo "You Entered Week Number $week_numeric is that correct? (Y/N) \c"
fi
Once you do it, it works fine.
b) Secondly, since you did not export
variable to the environment, it is not
visible outside the script.
To export any Shell variable, you do:
blah=whatever
export blah
c) What Shell are you using to test it?
I just did this and it worked fine:
# week=4
# week_numeric=`echo $week | tr -cd [0-9]`
# echo $week_numeric
4
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2009 08:02 PM
01-19-2009 08:02 PM
SolutionI'm not sure what you at trying to do here? Remove redundant whitespace?
>week_numeric=`echo $week | tr -cd [0-9]`
The first thing wrong is that you aren't quoting the tr(1) string:
week_numeric=$(echo $week | tr -cd "[0-9]")
The second thing is that you aren't using $().
>VK2COT:It is missing the "fi" to end the loop.
I assume that was covered by "...". :-)
>b) since you did not export variable to the environment
Why does a variable need to be exported?
>I just did this and it worked fine:
Because you didn't figure out all possible ways for the script to fail. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2009 08:12 AM
01-20-2009 08:12 AM
Re: /usr/bin/tr -cd [0-9] is not working for some users
week_numeric=`echo $week | tr -cd [0-9]`
Success one
week_numeric=$(echo $week | tr -cd "[0-9]")
week_numeric=`echo $week | tr -cd "[0-9]"`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2009 11:41 AM
01-20-2009 11:41 AM
Re: /usr/bin/tr -cd [0-9] is not working for some users
All this works fine. Again tested (this time
on my Fedora 10) server:
$ week=4
$ week_numeric1=`echo $week | tr -cd [0-9]`
$ week_numeric2=$(echo $week | tr -cd "[0-9]")
$ week_numeric3=`echo $week | tr -cd "[0-9]"`
$ echo $week_numeric1 $week_numeric2 $week_numeric
4 4 4
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2009 01:33 PM
01-20-2009 01:33 PM
Re: /usr/bin/tr -cd [0-9] is not working for some users
As soon as I mentioned quoting, it should be obvious why it failed. You need to create a file named "0" ... "9" to get it to fail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 05:46 AM
01-21-2009 05:46 AM
Re: /usr/bin/tr -cd [0-9] is not working for some users
in addtion to Dennis' comment:
You'll get different strange results, creating more than one file named 0...9 and depending on the input string (here: 11iv1):
# touch 1
# touch 0
# xx=week201
# echo $xx | tr -cd [0-9]
tr: The combination of options and String parameters is not legal.
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
tr [ -cd | -cs | -d | -s ] [-A] String1
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2009 08:10 AM
01-21-2009 08:10 AM