1829590 Members
7320 Online
109992 Solutions
New Discussion

Re: while -h

 
SOLVED
Go to solution
MarkSyder
Honored Contributor

while -h

Hi everybody.

I'm just debugging a shell script (that I didn't write) and it contains a line:

while -h $PRG

I can't find any reference to -h in any of my books or in a manual page. 10 points to the first person who tells me what -h means in this context. Further points to anyone who can tell me which manual page I will find it in.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
10 REPLIES 10
Pete Randall
Outstanding Contributor
Solution

Re: while -h

Mark,

ksh has a -h (but I don't think this is what you're looking for):

"-h Each command becomes a tracked alias when first encountered."

sh-posix has the same definition. Curious!


Pete

Pete
Tom Danzig
Honored Contributor

Re: while -h

Assuming POSIX shell:

-h file True, if file exists and is a symbolic link.

MarkSyder
Honored Contributor

Re: while -h

Thanks Pete and Tom.

Looking at the rest of the while loop, I think Tom's answer is the one that applies in this case. The script makes a lot more sense now.

Mark
The triumph of evil requires only that good men do nothing
Peter Godron
Honored Contributor

Re: while -h

Mark,
the -h is actually part of a test.
see man test for the full spec.
Regards
MarkSyder
Honored Contributor

Re: while -h

Thanks Peter.

Six points for telling me which manual page to look at.

This thread can now be considered closed.

Mark
The triumph of evil requires only that good men do nothing
Gerhard Roets
Esteemed Contributor

Re: while -h

Hi Mark

You do not need to concider a thread closed anymore. Look on the page and you will see a close thread button ;)

That will stop people like me replying after the fact :P

Gerhard
MarkSyder
Honored Contributor

Re: while -h

Hi Gerhard.

Please see http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=793765 - this thread persuaded me that the "close thread" feature is a bad thing that should be avoided (and preferably removed).

Mark
The triumph of evil requires only that good men do nothing
Jdamian
Respected Contributor

Re: while -h

I'm sorry but I understand nothing about this thread.

-h is used to test when condition is enclosed in (single or double) square brackets.

while [ -h $PRG ]

or

while [[ -h $PRG ]]

For me, an expression as

while -h $PRG

means '-h' is a command.
I've written down a script using this line and the error message is:

-h: not found
Gerhard Roets
Esteemed Contributor

Re: while -h

Hi Mark

Missed that one, I do agree with your thought process :)

Gerhard
Elmar P. Kolkman
Honored Contributor

Re: while -h

I agree with J Damien... while checks the result of the command you give next, in your case -h, while normally you do something like:
while [ -h $PRG ]

meaning '[' is the command being run. And '[' is linked to the test command.

So it seems you have:
1) a special shell, having a different while command
2) an alias for while (while="while test" or something like that, though I cannot get this to work)
3) an alias for -h (-h="test -h" (this works: alias -- -h="test -h")

Or some variant on these...
Every problem has at least one solution. Only some solutions are harder to find.