3

I have been working on creating new alias to use at work and noticed my .csh file filling with similar alias that go to different sub-directories but everything else is the same. I am newer at terminal alias and commands, and I was wondering if it was possible to create a catchall that can take the input and apply it to the alias as well as the directory?

Example:

alias ab1 "cd /home/drive/folder1/text/items && ll"
alias ab2 "cd /home/drive/folder2/text/items && ll"
alias ab3 "cd /home/drive/folder3/text/items && ll"

I was wanting to see if it was possible to have something like

alias ab* "cd /home/drive/folder*/text/items && ll"

And when I input ab2 it would auto fill the folder* directory to folder2.

When I use them, they are each run independently and very rarely run at the same time. I tried looking it up but was unsure on how to word it to correctly articulate my intention through search. Thank you ahead of time for any input.

muru
  • 207,228
Michael
  • 31

1 Answers1

1

Unlike the majority of shells (where you'd want to use a shell function for this kind of thing), the C shell supports parameterization of aliases:

~/dir> alias ab "echo /home/drive/\!:1/text/items"
~/dir> ab foo
/home/drive/foo/text/items
~/dir> ab bar
/home/drive/bar/text/items
~/dir>

So you should be able to do

alias ab "cd /home/drive/folder\!:1/text/items && ll"

then

ab 1
ab 2

etc.

See for example

steeldriver
  • 142,475