- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: implement option 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
тАО04-17-2011 06:12 PM
тАО04-17-2011 06:12 PM
I am writing the following script to check the file owner permission whether Write bit is enabled or not. The problem with this script is I still have problem to get it work with directory.
if the input is a directory i need to check whether those files in the directory has any file with write permission enabled, if so I will skip the files but will continue to copy over the rest of the files that meet requirement to the target together with directory and their associate subdirectory.
Also I was thought to implement -s and -t in the script so that I do not need to worry about the TGT variable which is the target filesystem.
Solved! Go to Solution.
- Tags:
- option
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2011 07:34 PM
тАО04-17-2011 07:34 PM
Re: implement option in script
while [ $# -gt 0 ]
do
case "$1" in
-s) src=$2;;
-t) tgt=$2;;
*) break;;
esac
shift
done
echo "cp -pr $src $tgt"
but it cannot process -s -t together and will extend after the -s
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2011 07:55 PM
тАО04-17-2011 07:55 PM
Re: implement option in script
while getopts s:t option
do
case "${option}"
in
s) src=${OPTARG};;
t) tgt=${OPTARG};;
*) break;;
esac
shift
done
echo "$src $tgt"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2011 08:23 PM
тАО04-17-2011 08:23 PM
Solution--------
#!/bin/sh
while [ $# -gt 0 ]
do
case "$1" in
-s)
src="$2"
shift #An extra shift here...
;;
-t)
tgt="$2"
shift #...and here
;;
*)
break
;;
esac
shift
done
echo "cp -pr $src $tgt"
--------
With getopts, you should indicate that both your options have arguments, so the correct optstring is "s:t:", not "s:t". When you're using getopts to parse options, don't use the "shift" command in the same loop.
-------
#!/bin/sh
while getopts s:t: option
do
case "${option}" in
s)
src="${OPTARG}"
;;
t)
tgt="${OPTARG}"
;;
*)
break
;;
esac
done
echo "$src $tgt"
-------
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2011 04:07 AM
тАО04-18-2011 04:07 AM
Re: implement option in script
In my opinion, using 'getopts' as soon as you have more than one option and/or argument is the appropriate course.
Useful programs tend to sprout more useful features. Having begun with getopts() to handle options and arguments offers an easy-to-amend framework.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2011 04:14 AM - last edited on тАО08-02-2011 01:18 PM by Kevin_Paul
тАО04-18-2011 04:14 AM - last edited on тАО08-02-2011 01:18 PM by Kevin_Paul
Re: implement option in script
HI (again):
You have a growing number of questions with unassigned points. Only about 3-of-10 of the responses you have received have been scored:
Please take a few minutes to show us what helped you and to say "thanks".
...JRF...