Ruth Schäfer

Sr. Research Software Engineer at Saga, Ph.D. in Particle Physics

Bash: goto script

A few weeks ago, my boss mentiones a little bash script to me that he wrote to switch between a list of directories in CLI without having to remember them all. I thought that seemed like a fun little exercise so I wrote a version myself this morning.

The behaviour is the following:

  • goto . saves the current path to the available paths.
  • goto lists all paths available for going to and prompts the user to choose one. It then cds to that path.
  • goto -c clears all paths currently saved.
  • goto -r removes a directory of the user’s choice from the list.
  • goto -h displays a helper

The code for this is on my gitlab at rrschafer/goto script. It is a good way to remind myself of the way conditions, math expressions, if and case statements and while loops over file contents work in bash.

Leave a Reply

Your email address will not be published. Required fields are marked *