2013-04-16 3 views
0

나는 대학 연구를위한 자료와 폴더, 학기으로 분류되어 있습니다 : 나는 그들 중 하나라는 이름의 디렉토리를 만들려고zsh에서 가장 높은 숫자로 대체하는 방법은 무엇입니까?

$ ls University 
semester1 semester2 semester3 semester4 

을, 나는 (가장 높은 숫자로 끝나는 디렉토리로 지적에 allways하는 zsh을 원하는 따라서 매 학기마다 디렉토리 단축키를 업데이트 할 필요가 없습니다.)

지금까지 난 단지 zsh을 확장에게 < 발견 -> :

$ ls semester<-> 
semester1 semester2 semester3 semester4 

을하지만 난 그에서 마지막이 dirname을 추출 할 수있는 방법을 찾을 수 없습니다.

진행 방법이나 변경해야 할 사항은 무엇입니까?

답변

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

은 실제로는

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

편집을 작동 : 그 첫 번째 버전 브래킷을 놓친 두 번째 줄, 고정. zsh을 설명서

[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. 
+0

에서

는 반드시 두 번째 예는 일이 있습니까? 어떤 이유로 든 – chepner

+0

, 나는 그것을 지적 해 주신 덕분에 잘못된 코드 (괄호가 빠졌습니다)를 작성했습니다. – Francisco

관련 문제