bug-bash
[Top][All Lists]
Advanced

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

Bash - various feature requests


From: Richard Neill
Subject: Bash - various feature requests
Date: Wed, 27 Dec 2006 23:03:31 +0000
User-agent: Thunderbird 1.5.0.8 (X11/20061115)

Dear All,

I hope I'm posting this in the right place, since it it's really a feature request, rather than a bug report. However, here are a few things which I think would be nice to have in bash, and easy to implement:

1)substr support for a negative length argument.
For example,
  stringZ=abcdef
  echo ${stringZ:2:-1}  #prints cde

i.e. ${string:x:y}
  returns the string, from start position x for y characters.
  but, if x is negative, start from the right hand side
  and if y is negative, print up to the end, -y.

This would work the same way as PHP, and be extremely useful for, say, removing an extension from a filename.
http://uk.php.net/manual/en/function.substr.php

---------------------------

2)"help strings" and "help operators"

Strings and operators are all documented in the man page. Likewise, there is an excellent guide here:
  http://www.die.net/doc/linux/abs-guide/string-manipulation.html

However, a quick reminder from within the shell (in the same way that 'for' and ':' are documented) would be really useful.


---------------------------

3)Some way to canonicalise a path. For example, converting:

  ./foo//bar/../baz.txt

to /home/foo/baz.txt


This isn't easy to do from a shell script. Maybe something like this could be a built in?
http://publicobject.com/2006/06/canonical-path-of-file-in-bash.html

There is a also a realpath program, but it seems not to be part of bash by default:
http://src.opensolaris.org/source/xref/sfw/usr/src/cmd/bash/bash-3.0/examples/loadables/realpath.c

---------------------------


4)A way to find a relative directory path. i.e. the solution to:

   If I were to start in directory  /home/me/x/y/z
   and I wanted to get to /home/me/x/a/b/c

   then, what argument would I need to provide to 'cd' ?

   #Answer is ../../b/c
   How could a shell script calculate this?

---------------------------

5)An enhancement to read/readline, such that one can specify the initial value with which the buffer is filled.

Currently, we can do:

  read -ep 'Enter your name: ' NAME

and I might type "Richad Neill".      #Note the deliberate typo.

If the script recognises this as invalid, the best it can do is:

  echo "Name not recognised"
  read -ep 'Re-enter your name: ' NAME

and the user must retype it in full.
I'd like to propose adding an "-i" option for initial value:

  echo "Name not recognised"
  read -ep "Please correct your name: " -i "$NAME"

The shell prints:
  Please correct your name: Richad Neill
where the latter part is now editable.

Thus the really nice editing features of readline can be used for updating values already stored in variables. This is extremely useful when the value is quite long.

---------------------------

I hope these thoughts are of some use. I'm not on this list, so please CC me with any followup. If this report could have been more useful, I'd welcome any feedback.

Best wishes,

Richard






















reply via email to

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