- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: bash and sh difference in break this while do ...
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
Forums
Discussions
Discussions
Discussions
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
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
02-10-2006 05:47 AM
02-10-2006 05:47 AM
bash and sh difference in break this while do loop
tfound=no
tmpdg=
mdm=
mda=
vxdisk -q list | \
while read da type dm grp state rest
do
if [ "$dm" = "$1" ]; then
tmpdg=$grp
mdm=$1
tfound=yes
break
elif [ "$da" = "$1" ]; then
if [ "$dm" != "-" ]; then
tmpdg=$grp
mdm=$dm
fi
tfound=yes
break
fi
done
if [ "$tfound" = "no" ]; then
abort "Disk $1 not found in configuration" vxvmshm:0
fi
Here's what I would like to explain: under bash (3.00.14) the tfound variable is set to "no" again after it is set to "yes" and breaks after the first if. Because of that the disk not found message is displayed and the script exits unsuccessfully.
This behavior does not happen under sh. It looks so simple but... why?
Thanks!
james
- Tags:
- bash
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2006 05:52 AM
02-10-2006 05:52 AM
Re: bash and sh difference in break this while do loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2006 06:00 AM
02-10-2006 06:00 AM
Re: bash and sh difference in break this while do loop
I'd use 'set -x' and perhaps add 'set -v' and trace the execution and variable setting.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2006 07:00 AM
02-10-2006 07:00 AM
Re: bash and sh difference in break this while do loop
Try this very simple test:
echo "One Two Three" | read A B C
echo "A = \"${A}\""
echo "B = \"${B}\""
echo "C = \"${C}\""
I think you will find different results in the POSIX shell and bash -- at least some implementations of bash. It's one of the reasons I'm not a huge fan of bash. My shell of choice under Linix is zsh.
- Tags:
- read
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2006 07:10 AM
02-10-2006 07:10 AM
Re: bash and sh difference in break this while do loop
if [ "$tfound" = "no" ]; then