I want to write a script to change directory, and list the destination directory's contents. Basically an alias that does cd and then ls.
So I wrote a script:
This does not have the expected behavior. When I run this script with my /media directory, it spits out the contents of the /media directory as requested, but when the script finishes, I am not cd'd to that directory. Apparently the shell forks a new shell when it runs the script and returns me to my current shell when it's finished.
How can I write a script to cd?
Also, I've noticed that I cannot do
which myscript | cd
Any insight as to why is appreciated.