- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Aliases for values in Shell Scripts
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
тАО08-07-2006 01:35 PM
тАО08-07-2006 01:35 PM
Aliases for values in Shell Scripts
Is there such a thing as designating aliases for values in a shell script. for example:
echo "do you want to..."
read variable
case $variable in
y )do_command
;;
n )do_other_command
;;
esac
Now suppose that I want to do_command also if variable equals Y, yes, ok, or "" (return)?
Is there a way to declare all these values equal to each other (especially globally), so I don't have to redundantly list each possibility, or have a long string of "OR"s in an if statement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2006 01:41 PM
тАО08-07-2006 01:41 PM
Re: Aliases for values in Shell Scripts
I would also check the $variable and if it is blank, then set it to yes if that is your default.
if [[ "${variable}" = "" ]] ; then
variable=y
fi
case $variable in
y|Y|yes|Yes|YES|OK|ok) do_command ;;
n|N|No|NO) do_other_command ;;
*) error ;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2006 01:47 PM
тАО08-07-2006 01:47 PM
Re: Aliases for values in Shell Scripts
y|Y|yes|Yes|ok|OK) do_command
;;
but you can make your task much easier by forcing the variable to lowercase:
typeset -l lcvar=""
typeset variable=""
read variable
lvcar=${variable) # convert to lowercase
case ${lcvar} in
y|yes|okay|ok) do_command;;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-08-2006 01:30 AM
тАО08-08-2006 01:30 AM
Re: Aliases for values in Shell Scripts
There seems to be a LOT of different little nuances in this stuff. There are a lot of pages and tutorials out there, but they each seem to cover real basic stuff, or little nips and tucks here and there.
If you can recommend a good, comprehensive tutorial, especially one covering bash, I would be very happy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-08-2006 01:33 AM
тАО08-08-2006 01:33 AM
Re: Aliases for values in Shell Scripts
This isn't exacatly a tutorial, but its an excellent guide:
http://www.gnu.org/software/bash/manual/bash.html
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-08-2006 01:40 AM
тАО08-08-2006 01:40 AM
Re: Aliases for values in Shell Scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-08-2006 05:49 AM
тАО08-08-2006 05:49 AM
Re: Aliases for values in Shell Scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2006 02:04 PM
тАО08-10-2006 02:04 PM