별칭 중첩 문자열

별칭 중첩 문자열

내 파일 에 몇 가지 인수를 추가하는 aliasfor 가 있습니다 . 나는 이것이 수행되는 방식과 비슷한 별도의 터미널에서 이것을 실행하고 싶습니다youtube_dl.bashrc여기. 문제는 이것이 문자열을 입력으로 사용한다는 것입니다.

내 현재 별칭:

alias youtube-dl="youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"

새 별칭이 어떻게 보이길 원하는지 :

alias youtube-dl='gnome-terminal -e "youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"'

그러나 문제는 이제 -string이 '두 개의 별도 문자열로 해석된다는 것입니다. 또한 이제 URL을 인수로 추가할 수 없습니다. 이 문제를 어떻게 피합니까?

답변1

따옴표를 사용하여 이스케이프를 처리할 수도 있지만 나는 인용 수준을 줄이는 방법을 찾는 것을 선호합니다. 예를 들어 다음을 사용할 수 있습니다.gnome-terminal -x대신에:

-e, --command=STRING
         Execute the argument to this option inside the terminal.

-x, --execute
         Execute  the  remainder  of  the  command  line  inside   the
         terminal.

그래서,

gnome-terminal -e "youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"

다음과 같이 됩니다:

gnome-terminal -x youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'

한 겹의 인용문을 깎아냅니다. 별칭은 다음과 같습니다.

alias youtube-dl='gnome-terminal -x youtube-dl -ci --restrict-filenames -o "%(title)s.%(ext)s"'

아니면 다음과 같은 함수를 사용할 수도 있습니다.

youtube-dl()
{
    gnome-terminal -x youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s' "$@"
}

관련 정보