HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help with a shell script
Operating System - HP-UX
1826345
Members
3860
Online
109692
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
Discussions
Forums
Discussions
back
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
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
11-16-2010 03:52 AM
11-16-2010 03:52 AM
Hi,
I am completely new to scripts and shell scripts.
I am looking to write a shell script to find the files in a catelog and print out..
like the script should search for a Parameter which is the name of a catalog... and check the existance of the catalog...If it does not exist throw an error else find the files that exists within this catalog excluding the subcatalogs and with the help of command anything like “list_files” and shows the type of each file
I am completely new to scripts and shell scripts.
I am looking to write a shell script to find the files in a catelog and print out..
like the script should search for a Parameter which is the name of a catalog... and check the existance of the catalog...If it does not exist throw an error else find the files that exists within this catalog excluding the subcatalogs and with the help of command anything like “list_files” and shows the type of each file
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2010 04:35 AM
11-16-2010 04:35 AM
Solution
Hi Mike:
If by "catalog" you mean a directory consider the following:
# cat ./mysh
#!/bin/sh
typeset DIR=$1
if [ ! -d "${DIR}" ]; then
echo "'${DIR}' is not a directory"
exit 1
fi
find ${DIR} -xdev -exec ls -ld {} +
exit 0
...pass as an argument, the name of a directory that you want to examine; as for example:
# ./mysh /home/mike
The script validates that the first argument passed is a directory and exits if not. If the directory test is passed, a 'find()' is used to run a 'ls' command for every file and subdirectory found. The '-xdev' argument to find() prevents the search from leaving the filesystem in which the directory occurs. The "+" terminator to the '-exec' argument improves performance by bundling many arguments together for each invocation of 'ls'.
For a good, beginning guide to shells and shell scripting, see:
http://docs.hp.com/en/B2355-90046/index.html
Learn the Posix shell which is the HP standard and a superset of the Korn88 ('ksh') shell. Avoid the C shell as it is fraught with dysfunctional features.
Regards!
...JRF...
If by "catalog" you mean a directory consider the following:
# cat ./mysh
#!/bin/sh
typeset DIR=$1
if [ ! -d "${DIR}" ]; then
echo "'${DIR}' is not a directory"
exit 1
fi
find ${DIR} -xdev -exec ls -ld {} +
exit 0
...pass as an argument, the name of a directory that you want to examine; as for example:
# ./mysh /home/mike
The script validates that the first argument passed is a directory and exits if not. If the directory test is passed, a 'find()' is used to run a 'ls' command for every file and subdirectory found. The '-xdev' argument to find() prevents the search from leaving the filesystem in which the directory occurs. The "+" terminator to the '-exec' argument improves performance by bundling many arguments together for each invocation of 'ls'.
For a good, beginning guide to shells and shell scripting, see:
http://docs.hp.com/en/B2355-90046/index.html
Learn the Posix shell which is the HP standard and a superset of the Korn88 ('ksh') shell. Avoid the C shell as it is fraught with dysfunctional features.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2010 06:06 AM
11-16-2010 06:06 AM
Re: help with a shell script
Thanks JRF ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2010 06:25 AM
11-16-2010 06:25 AM
Re: help with a shell script
Hi (again) Mike:
If you change:
typeset DIR=$1
...to:
typeset DIR=${1:-.}
...then you can always search the current directory by omitting any argument to the script.
The notation '${parameter :-word }' says that if the parameter is set and is nonnull, substitute its value; otherwise, substitute word. In this case, "word" is a dot ('.') which means the current directory.
Don't forget to look at and use the 'sh-posix(1)' manpages. There is a wealth of good information there.
Regards!
...JRF...
If you change:
typeset DIR=$1
...to:
typeset DIR=${1:-.}
...then you can always search the current directory by omitting any argument to the script.
The notation '${parameter :-word }' says that if the parameter is set and is nonnull, substitute its value; otherwise, substitute word. In this case, "word" is a dot ('.') which means the current directory.
Don't forget to look at and use the 'sh-posix(1)' manpages. There is a wealth of good information there.
Regards!
...JRF...
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
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP