- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Accept caps and lowercase in script
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
Discussions
Discussions
Forums
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
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
тАО06-16-2009 06:51 AM
тАО06-16-2009 06:51 AM
I have the following:
elif [ $ANS = ALL ]; then
echo "worked"
My script works great if the input is exactly ALL. How do I allow "all" "All" etc...
Solved! Go to Solution.
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 06:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 07:53 AM
тАО06-16-2009 07:53 AM
Re: Accept caps and lowercase in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 08:15 AM
тАО06-16-2009 08:15 AM
Re: Accept caps and lowercase in script
also, numeric entries should not matter as they will be interpreted as strings. It will be a problem if you making a numeric comparison in your if [] constructs, but for the code segment you provided, entering numerics is fine
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 08:16 AM
тАО06-16-2009 08:16 AM
Re: Accept caps and lowercase in script
I think you missed my point:
# typeset -l ANS;read ANS;[ "$ANS" = "all" ] && echo "OK" || echo "NOT_OK"
> Also, sometimes the ans will be numeric...will typeset -l cause problems with that?
No, the conversion to all lowercase only affects letters.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 08:51 AM
тАО06-16-2009 08:51 AM
Re: Accept caps and lowercase in script
out=/tmp/omni.out
if [ -f $out ]; then
rm $out
fi
ps -ef |grep -i omni |awk '{print $2}' >$out
ps -ef |grep -i omni
echo "Please select the Process ID to kill (second column),"
echo " or type all if you want all omni processes killed. \n"
typeset -l ANS
read ANS
if grep -q $ANS $out; then
echo "This is a valid PID...killing process"
# /usr/local/bin/sudo kill -9 $ANS
elif [ $ANS = ALL ]; then
echo "All omni processes will be terminated"
# for i in `cat $out`; do
# /usr/local/bin/sudo kill -9 $i
# done
else
echo "This PID is not valid. Run the script again and"
echo "select your PID from the second column, or type ALL to kill all omni processes."
fi
rm $out
Output:
Please select the Process ID to kill (second column),
or type all if you want all omni processes killed.
all ->input by me
This PID is not valid. Run the script again and
select your PID from the second column, or type ALL to kill all omni processes.
I also typed ALL and it didn't like it either. When typeset -l isn't there I can type ALL and it works....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 08:53 AM
тАО06-16-2009 08:53 AM
Re: Accept caps and lowercase in script
[$ANS = ALL] and should be [ $ANS = all ]
Thanks...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 09:00 AM
тАО06-16-2009 09:00 AM
Re: Accept caps and lowercase in script
By using the 'typeset -l' _every_ letter is translated to lowercase in the variable typeset!
Your test:
[ $ANS = ALL ]
...will never evaluate true. You want to make it:
[ $ANS = all ]
After all (no pun) this allows you to say "ALL", "All", "aLL" or "aLl" any way you choose!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 09:14 AM
тАО06-16-2009 09:14 AM
Re: Accept caps and lowercase in script
Seems like its time to actually test your script, versus asking us to evaluate it.
Resources
http://www.unix.com/shell-programming-scripting/31743-accepting-upper-lower-case.html
http://www.daniweb.com/forums/thread136257.html
Converting input:
http://www.cyberciti.biz/faq/linux-unix-shell-programming-converting-lowercase-uppercase/
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-17-2009 06:01 AM
тАО06-17-2009 06:01 AM
Re: Accept caps and lowercase in script
case $ANS in
case ALL|all)
Commands goes here
;;
case [Aa][Ll][Ll])
This method should work too, commands goes here
;;
case *)
if it didn't match, commands goes here
;;
esac
Best regards
Fredrik eriksson