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

 
 

sr #104821: Wish: string function aliases

Submitted by:  Richard Neill <richardneill>
Submitted on:  Wed 09 Nov 2005 04:21:27 AM UTC  
 
Category: NonePriority: 5 - Normal
Severity: 1 - WishStatus: None
Privacy: PublicAssigned to: None
Open/Closed: OpenOperating System: None

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

No Changes Have Been Made to This Item

Back to the top


Powered by Savane 3.1-cleanup