- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 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
тАО08-28-2006 11:21 AM
тАО08-28-2006 11:21 AM
script
for i 'cat /foo/users.list' : do
if [[ ! -a $i ]] ; then
mkdir $i
done
what is the "-a" doing too please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 11:46 AM
тАО08-28-2006 11:46 AM
Re: script
To the internal evaluator "-a" says does a file exist? Thus, [[ ! -a ${i} ]] says if file ${i} does not exist then mkdir ${i}(and a file in UNIX is a regular file, a directory, a device node, ...).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 11:49 AM
тАО08-28-2006 11:49 AM
Re: script
The double-bracket is the the preferred approach these days because it is more efficient in that no external process need be fork()'ed and exec()'ed to do the expression evaluation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 12:21 PM
тАО08-28-2006 12:21 PM
Re: script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 02:13 PM
тАО08-28-2006 02:13 PM
Re: script
it says in the manual that the "!". "inverts the exit status of the command to which it is applied and it also inverts the meaning of the test operator"
I am a bit confused. you can tell me to go back and read more if you like LOL LOL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 02:32 PM
тАО08-28-2006 02:32 PM
Re: script
Also consider that in the CWD that directory (or file) Minnie already exists.
The directory is only created if no such entry is found so the loop would create directories Mickey and Pluto but would not create Minnie because that directory already existed.
In that sense the correct approach is "if file (directory) does not exist then make it".
I should point out that there is actually a syntax error because you are missing an "fi".
for i 'cat /foo/users.list' : do
if [[ ! -a $i ]] ; then
mkdir $i
done
should be:
for i in 'cat /foo/users.list'
do
if [[ ! -a ${i} ]]
then
mkdir ${i}
fi
done
but because filenames can contain whitespace which would drive your for statement nuts, a better approach is something like this:
typeset i=""
cat /foo/users.list | while read i
do
if [[ ! -a "${i}" ]]
then
mkdir "${i}"
fi
done
and the cat is superfluous as well since you could simply redirect stdin on the read itself but I left the cat in because it is closer to your original. Notice the quotes around "${i}" -- this means that directory "Mickey Mouse" is handled as one filename -- as it should be. Whitespace in UNIX filenames is perfectly legal although many scripts and programs will incorrectly handle it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 02:41 PM
тАО08-28-2006 02:41 PM
Re: script
I am starting to see the light, cool man.
thanks very much.
wicked
cheers