mainThe GNU Bourne-Again SHell - Support: sr #104821, Wish: string function aliases

 
 

sr #104821: Wish: string function aliases

Submitter:  Richard Neill <richardneill>
Submitted:  Wed 09 Nov 2005 04:21:27 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  1 - Wish Status:  Wont Do
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 25 Mar 2015 02:46:08 PM UTC, comment #3: 

Not needed,

Bash is based on the POSIX shell standard, these are not "arcane" functions, these are standard. And for your second point, it'd be easier to understand other people's scripts if you actually bothered learning bash.

Anonymous
Fri 11 Nov 2005 07:08:21 PM UTC, comment #2: 

Thanks for your comment. I know that I can do this using shell functions. However, I'm suggesting that these shell functions should be shipped by default inside all versions of bash. This will solve 2 problems:

1)One of the hardest things to learn about bash scripting is string handling. It is just so very arcane.

2)It's difficult to make sense of other people's scripts which use the inbuilt string handling.

The consequence of these is that perl tends to get used instead.

I realise that it will take at least 5 years before it becomes safe to use these widely in "portable" scripts, but if we start now...

Richard Neill <richardneill>
Fri 11 Nov 2005 05:51:49 PM UTC, comment #1: 

You can easily implement whatever string functions you want as shell functions. For example, this:

function strlen
{
    echo ${#1}
}

and then
$ strlen bash
4
$ LEN=$(strlen "hello world")
$ echo $LEN
11
$ echo Your name is $(strlen $LOGNAME) characters long.
Your name is 9 characters long.

... etc ...

Anonymous
Wed 09 Nov 2005 04:21:27 AM UTC, original submission:  

Some of the bash string functions are unintuitive, to say the least. For example
  ${#VARIABLE}
is not, to my mind, as clear as
  strlen $VARIABLE

Likewise,
  ${stringZ/abc/xyz}
would be much easier to understand if written as
  strreplace stringZ abc xyz
It would also be easier to handle metacharacters this way, and easier to look up "help strreplace".

What I am requesting are a few predefined fucntions (substr, strlen, etc) that refer to the normal bash string handling, but with a less gruesome syntax.

My suggestion is that, by introducing these now, in 5 years' time it may be safe to use them in most shell scripts, and then one of the annoyances of bash will be gone.

I think that the performance penalty would be almost zero, but the result would be a large increase in readability. Of course, the old ways wouldn't vanish.

Naturally, this is just a personal view, but I do quite a bit of bash scripting, and even I never remember all of these!

If you disagree, perhaps implementing "help string" or "help substr" etc would be a good alternative. Thus documenting the functions that don't exist, but that people are looking for, and giving a pointer to where they might be found.

Thanks very much for all your work - much appreciated.




Richard Neill <richardneill>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Updated the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-12 chet StatusNone Wont Do

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code