cd patch

closed account (Dy7SLyTq)
so one thing that really bugged me about the linux cd was if i had lets say this in folder temp:
main.cpp
a.out
connect.exe
download_files (which is a directory)

and did cd * it would say something like bash: cd: a.out: Not a directory. so i was thinking of implementing an ls like thing where it tests if its a dir before trying to cd to it. i did some research and found that cd is a part of the terminal, so i was wondering would it be possible to get the source and do that? im not new to linux but i havent delved to deep into the development of it to know how viable an option that is
Suppose that you've got several directories, ¿what do you expect `cd *' to do?

> where it tests if its a dir before trying to cd to it
¿how it would be different on what already does?
if you try do `cd main.cpp' it fails gracefully.


FYI, */ would match the directories
You could also use tab-completion
closed account (Dy7SLyTq)
Suppose that you've got several directories, ¿what do you expect `cd *' to do?

go to the first directory. its nothing life changing. just a small hack


¿how it would be different on what already does?
if you try do `cd main.cpp' it fails gracefully.

it doesnt. it tries to move to that dir and if it can it will. what my code would do is iterate through the files in the dir specified until it finds a sub dir and switches to it, and if it doesnt find one give an error

FYI, */ would match the directories

thanks didnt know that. sounds like what i was trying to implement

You could also use tab-completion

whats that?
You need to take a look at globbing. * is handled by the shell and expands to the entries in the current directory.

One way to see the what * expands to is:
 
for f in *; do echo $f; done


When you type ls *, do you think ls expands *? It doesn't, the names are passed to ls.

Given all that, do think that what you think you want cd * to do is consistent with the rest of the system? Do you want ls * to list only the first directory if there is one?

http://en.wikipedia.org/wiki/Glob_%28programming%29
http://unixhelp.ed.ac.uk/CGI/man-cgi?glob+7
Last edited on
closed account (Dy7SLyTq)
ah never mind. i didnt know about all of that
Topic archived. No new replies allowed.