0

I have a folder with materials for university study, sorted by semesters:

$ ls University
semester1 semester2 semester3 semester4

I'm trying to make one of them the named directory, and I want zsh to allways pointed to directory ending with highest number (so I don't have to update my directory shortcut every semester).

So far I found only the zsh expansion <->:

$ ls semester<->
semester1 semester2 semester3 semester4

but I cannot find a way to extract only the last dirname from that.

Any idea how I should proceed or what I should change?

khardix
  • 1
  • 1

1 Answers1

1
latestSemester=`ls semester<-> | tail -1`
echo $latestSemester

actually this also works

latestSemester=`ls semester<->([-1])`

EDIT: Fixed the second line, whose first version missed brackets.

From the zsh manual

[beg[,end]]
    specifies which of the matched filenames should be included in the returned list. The
    syntax is the same as for array subscripts. beg and the optional end may be mathemat-
    ical expressions. As in parameter subscripting they may  be  negative  to  make  them
    count  from the last match backward. E.g.: ‘*(-OL[1,3])’ gives a list of the names of
    the three largest files.
Francisco
  • 3,980
  • 1
  • 23
  • 27