mainThe GNU Bourne-Again SHell - Support: sr #110245, Feature Request: Enable the cd...

 
 

sr #110245: Feature Request: Enable the cd command to change to another directory by replacing strings

Submitter:  None
Submitted:  Sat 06 Jun 2020 12:57:19 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Wont Do
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 22 Jun 2020 09:15:39 AM UTC, comment #2: 

Thanks for the pointer. Maybe the existence of the examples/functions directory could be mentioned somehow in man bash?
I am fine with closing this item.

Anonymous
Tue 16 Jun 2020 06:45:27 PM UTC, comment #1: 

This, and other ksh features, is trivial to implement using a shell function. There are a few sample shell functions that do this and additional things in the examples/functions directory of the bash distribution.

There's no need to make this part of the bash source.

Chet Ramey <chet>
Group administrator
Sat 06 Jun 2020 12:57:19 PM UTC, original submission:  

In Korn Shell, it is possible to change to another directory by replacing a string of the current directory, as in the following example:

$ pwd
/usr/lib/motd.d
$ cd usr/lib etc
/usr/lib/motd.d
$ pwd
/etc/motd.d

The current behavior of bash in Fedora 32 (version 5.0.17(1)-release (x86_64-redhat-linux-gnu)) is:
$ cd usr/lib etc
bash: cd: too many arguments

I can emulate the ksh behavior with the following function:

# emulate ksh cd behavior:
function cd () {
   if [[ $# -eq 2 ]]; then
      _NEWWD=${PWD/${1}/${2}}
      builtin cd ${_NEWWD}
   else
      builtin cd ${1}
   fi
}

but I'd rather like to have this feature in bash's builtin cd command.

Anonymous

 

(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 (Posted a comment)
  • -email is unavailable- added by None (Submitted 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
    2020-06-16 chet StatusNone Wont Do

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code