Home > Back-end >  How i can unserialize string by bash?
How i can unserialize string by bash?

Time:11-11

I have a string s:4:"Test"; from my previous question. How I can unserialize it and get just a Test string?

CodePudding user response:

This will output Test:

str='s:4:"Test";' # Initial string
s=${str//[:0-9\";]/} # Remove digits, quote, colon, semicolon
echo ${s:1} # Drop the first character

CodePudding user response:

It works for me:

echo 's:4:"Test";' | sed -e 's/.*"\(.*\)".*/\1/'

But it don't works for multiline string

  • Related