GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script: case
Operating System - HP-UX
1848939
Members
7214
Online
104039
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
back
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
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
02-26-2003 06:15 AM
02-26-2003 06:15 AM
Hi,
I need to do a script using case.
(case ... in )
Could someone give me an example?
thank you
I need to do a script using case.
(case ... in )
Could someone give me an example?
thank you
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 06:17 AM
02-26-2003 06:17 AM
Re: script: case
Here is some example case usage that we use to test conditions for a backup:
# TEST FOR CORRECT USAGE:
# # Ensure root is executing the script
UID=`/usr/bin/id -u` # Test the user id
case "$UID" in # Is it root?
0) # Do nothing user is root
;; # Otherwise...
*) echo "$BELL" # Ring the bell
echo "$USAGE" # Display the usage message
exit 1; # Abort the script
esac
# # Test the number of arguments
case "$#" in # How many arguments passed?
1) # Do nothing this is correct
;; # Otherwise...
*) echo "$BELL" # Ring the bell
echo "$USAGE" # Display the usage message
exit 1;; # Abort the script
esac
# # Test the argument passed
case "$1" in # What is the argument set to?
-o|-O) ;; # Undocumented see below
-f|-F) MODE="Full";; # Set up for weekly full backup
-i|-I) MODE="Incremental";; # Set up for daily incremental backup
-m|-M) MODE="MonthEnd" # Set up for month end full backup
;; # Otherwise...
*) echo "$BELL" # Ring the bell
echo "$USAGE" # Display the usage message
exit 1;; # Abort the script
esac
# TEST FOR CORRECT USAGE:
# # Ensure root is executing the script
UID=`/usr/bin/id -u` # Test the user id
case "$UID" in # Is it root?
0) # Do nothing user is root
;; # Otherwise...
*) echo "$BELL" # Ring the bell
echo "$USAGE" # Display the usage message
exit 1; # Abort the script
esac
# # Test the number of arguments
case "$#" in # How many arguments passed?
1) # Do nothing this is correct
;; # Otherwise...
*) echo "$BELL" # Ring the bell
echo "$USAGE" # Display the usage message
exit 1;; # Abort the script
esac
# # Test the argument passed
case "$1" in # What is the argument set to?
-o|-O) ;; # Undocumented see below
-f|-F) MODE="Full";; # Set up for weekly full backup
-i|-I) MODE="Incremental";; # Set up for daily incremental backup
-m|-M) MODE="MonthEnd" # Set up for month end full backup
;; # Otherwise...
*) echo "$BELL" # Ring the bell
echo "$USAGE" # Display the usage message
exit 1;; # Abort the script
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 06:17 AM
02-26-2003 06:17 AM
Re: script: case
Hi
echo "input: \c"
read var
case "$var"
in
1)
echo 1;;
2)
echo 2;;
*)
echo "something else";;
esac
Chris
echo "input: \c"
read var
case "$var"
in
1)
echo 1;;
2)
echo 2;;
*)
echo "something else";;
esac
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 06:24 AM
02-26-2003 06:24 AM
Solution
Hi
echo "would you like a drink Yy or Nn \c"
read ans
case $ans in
Y|y) echo "I'll put the kettle on"
;;
n|N) echo "Ok"
;;
*) echo " Please reply Yy Nn "
;;
esac
You can see the actions are dependant upon the replay of the question
The construct is straight forward but obviously gets more complicated as you require more actions to be performed
Have a look here for tonnes of reference areas
http://forums.itrc.hp.com/cm/QuestionAnswer/0,,0xbb5e7e990647d4118fee0090279cd0f9,00.html
HTH
Steve
echo "would you like a drink Yy or Nn \c"
read ans
case $ans in
Y|y) echo "I'll put the kettle on"
;;
n|N) echo "Ok"
;;
*) echo " Please reply Yy Nn "
;;
esac
You can see the actions are dependant upon the replay of the question
The construct is straight forward but obviously gets more complicated as you require more actions to be performed
Have a look here for tonnes of reference areas
http://forums.itrc.hp.com/cm/QuestionAnswer/0,,0xbb5e7e990647d4118fee0090279cd0f9,00.html
HTH
Steve
take your time and think things through
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP