For my first bash script, I want to create something that's really been annoying me: when I switch folders, I want the contents of that folder to be displated automatically. I tried adding this following code to ~/.bashrc:
alias go='cd; ls'
Simple enough I thought! Not so. While typing go /etc
does indeed list the contents of /etc, my working directory hasn't actually changed, I'm still in the one I was in before. How do I remedy this?
ls
ifcd
is successful:go() { cd "$1" && ls; }
-- this avoids listing the current directory if the parameter does not exist. – glenn jackman Aug 11 '14 at 19:10$1
first argument passed to command - this also follows on with$2
for the second,$3
for the third, etc.$@
can also be used to represents all of the arguments. Various examples can be found - e.g this. – Wilf Aug 11 '14 at 20:12