skip to Main Content

I’m using this in my script and it works fine on my root server and on some others I tested.

But there’s a problem when using it on my webhosting (Hosted Plesk): The chrooted shell, it doesn’t output anything. Just quits. My webhoster said I need to use the absolute paths, but I dont know how to apply this on the bash rematch.

#!/bin/bash 
str='"<result="Abc1234" />"'
regex='<result="([0-9a-zA-Z._-/:]*)" />'
[[ $str =~ $regex ]] && echo ${BASH_REMATCH[1]}

(My first post here, sorry if I forgot something or misformatted this whole post)

2

Answers


  1. Instead of:

    regex='<result="([0-9a-zA-Z._-/:]*)" />'
    

    say:

    regex='<result="([0-9a-zA-Z._/:-]*)" />'
    

    - is moved to where it no longer can be considered meaning a range.

    Actually I am a surprised it worked on the other system. I’ve replaced && echo ${BASH_REMATCH[1]} with ; echo $? (this was another possible debugging step) and was getting 2 which according to man bash means “syntactically incorrect regular expression”.

    If this doesn’t help. Than we must be seeing different reason, way our shell interpret the script, but in any case printing the return status could then be the next step to take.

    Login or Signup to reply.
  2. In the discussion below the question it turned out that the issue is related to different default locales on the servers. Make sure that you are running the command with the right locale:

    LANG=en_US.UTF-8 bash script.sh
    

    (en_US.UTF-8) turned out to be the right locale in your case.


    PS: Please also keep in mind what Ondrej K. says.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search