Often I run into a problem, I need to create a directory using mkdir and I have to cd into it. Some times I need to create a directory structure like this: ~/code/folder/sub_folder, the folder might be missing or the code might be missing. So I found the following shell command which will mkdir with padding and changes i.e cd to the created directory.
Nice short helper!
Why would you
eval cd "\"\$$#\""
??? So you’re passing all arguments tomkdir
potentially making several folders (mkcd test1/foo1 test2/foo2
), then moving into the last provided argument ($# is 1 when there is one argument and $1 is the argument) via some exec magic. To be fair it does look safe (but execs always look safe :D) but why not move into the first provided argument instead (&& cp "$1"
) and avoid that dance entirely?