Find the answer to your Linux question:
Results 1 to 3 of 3
when I exec RAID_FAILDEV_CHK=$(mdadm --detail /dev/md0 | grep -Z "Failed Devices") RAID_FAILDEV_CHK will have the string "Failed Devices : 0" The problem is that if I do if [ "$RAID_FAILDEV_CHK" ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    2

    removing invisible character

    when I exec

    RAID_FAILDEV_CHK=$(mdadm --detail /dev/md0 | grep -Z "Failed Devices")

    RAID_FAILDEV_CHK will have the string "Failed Devices : 0"


    The problem is that if I do

    if [ "$RAID_FAILDEV_CHK" = "Failed Devices : 0" ]

    I get false. Why? I think there is a trailing return char in variable $RAID_FAILDEV_CHK. If so, how do I remove that char?

  2. #2
    Just Joined!
    Join Date
    Nov 2009
    Posts
    2
    I found the problem.

    The command

    RAID_FAILDEV_CHK=$(mdadm --detail /dev/md0 | grep -Z "Failed Devices")

    will put " Failed Devices : 0" in variable RAID_FAILDEV_CHK. Notice the space in front of "Failed"

    This is why

    if [ "$RAID_FAILDEV_CHK" = "Failed Devices : 0" ]

    will always return false.

    Can somebody tell me why there's a space in front of "failed"?

  3. #3
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Quote Originally Posted by david90 View Post
    when I exec

    RAID_FAILDEV_CHK=$(mdadm --detail /dev/md0 | grep -Z "Failed Devices")
    man grep (hint: should be -o if you want RAID_FAILDEV_CHK to contain exactly the phrase "Failed Devices).

    in short, you used the wrong grep option.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...