- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Newbie sh-posix question about While loop
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
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
тАО06-24-2004 01:49 AM
тАО06-24-2004 01:49 AM
while [[ $I -lt $CNT ]];
do
if [[ `grep ${VOLUMES[$I]} *postBackup | grep "has been successfully removed" | wc -l` -eq 1 ]]
let SucessfullyMerged = $SucessfullyMerged + 1
echo ${VOLUMES[$I]}
let I=$I+1;
done
It generates this error message:
./BackupStatus[16]: Syntax error at line 23 : `done' is not expected.
In my script, line 23 is the line immediately after the done. I'm kind of new to this, can someone tell me what I'm doing wrong?
Thanks,
Jason
Solved! Go to Solution.
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2004 01:53 AM
- Tags:
- fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2004 01:55 AM
тАО06-24-2004 01:55 AM
Re: Newbie sh-posix question about While loop
if
then
else
fi
Hope this helps.
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2004 01:57 AM
тАО06-24-2004 01:57 AM
Re: Newbie sh-posix question about While loop
if [[ some_condition ]]
then
command1
command2
fi
Lose the semicolon in let I=$I + 1, if fact better syntax is is simply
((I += 1))
Learn to enclose ALL variables in {}.
Start using the typeset command to type variables so that instead of
I=0
do
typeset -i10 I=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2004 02:05 AM
тАО06-24-2004 02:05 AM
Re: Newbie sh-posix question about While loop
Learn to enclose ALL variables in {}.
Start using the typeset command to type variables so that instead of
I=0
do
typeset -i10 I=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2004 02:19 AM
тАО06-24-2004 02:19 AM
Re: Newbie sh-posix question about While loop
The typeset is the preferred method nowadays. It gives the shell intepreter hints about how a given variable should be treated and what are legal operations to perform on it. Typesetting also avoids ambiguities and the radix (base) of a given integer variable which in turn avoids problems. For example, consider:
I=08
Now that might be an error if your intent was to create an octal number (or if you grabbed 08 out of a cal command) BUT if
you first did:
typeset -i10 I
then
I=08
or
I=8
would be correctly interpreted in either case.
Since you indicated that you were a newbie, learn the disciplined approach early and you won't need to unlearn less than well-disciplined habits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2004 04:56 AM
тАО06-24-2004 04:56 AM
Re: Newbie sh-posix question about While loop
I would also clean up your grep statement. Either:
if grep "${VOLUMES[$I]}.*has been successfully removed" *postBackup
or
cnt=$(grep -c "${VOLUMES[$I]}.*has been successfully removed" *postBackup)
if ((cnt == 1))
. . . depending on whether you need to check for any occurence of the line (first example) or just one occurence of the line (second example).
Notice the $() - this is the POSIX shell's command substitution syntax and is more robust than the back ticks.
Also, you do not need to use the "$" when using let or (( )). ((i = i + 1)) or ((i += 1)) or let "i += 1"
Dan