[Top][All Lists]

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

Feature Request: Python-like string split and join

From: William Park
Subject: Feature Request: Python-like string split and join
Date: Sat, 23 Jan 2021 21:21:37 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

If separator is a single character, then shell can split a string or
join arguments.  But, if separator is string, then it gets messy.  We
shouldn't have to resort to Awk/Python for that.

How about Python-like string split and string join?

${parameter...} is overloaded as is, and we are running out of special
characters.  So, how about, just appending at the end of parameter
expansion syntax?  
    ${parameter...} is already existing expansion, and
    sep is substring to join, if ${parameter...} is multiple argument
        syntax involving '*', like ${*}, ${*:10:10}, ${array[*]:20}, and
    sep is substring to split on, if ${parameter...} is single string
        syntax like ${var}, ${var:3:10}, ${1}, ${10:2:4}

    array=( "${var;.}" )
would be equivalent to
    IFS=. read -a array <<< "$var"
    echo "${*;.}"
would be equivalent to
    (IFS=.; echo "$*")

Where it would be used?
    - everywhere

    - replaces multiple lines in shell function
    - makes Bash script simpler and clearer
    - less bookkeeping and less mistakes

William Park <opengeometry@yahoo.ca>

reply via email to

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