help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tokenize honoring quotes


From: Robert E. Griffith
Subject: tokenize honoring quotes
Date: Fri, 5 Aug 2022 13:43:53 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

Is there an efficient native bash way to tokenize a string into an array honoring potentially nested double and single quotes?

For example...

   $ str='echo "hello world"'
   $ read -e -a tokens <<<"$str
   ...
   tokens[]
          [0]='echo'
          [1]='"hello'
          [2]='world"'

   In this example, I want tokens to have just two elements like...

   tokens[]
          [0]='echo'
          [1]='"hello world"'
I don't care much weather the quoted token retains the quotes or not.

--BobG



reply via email to

[Prev in Thread] Current Thread [Next in Thread]