내 환경 설정을 자동화하려고합니다. 이렇게하면 터미널에서 여러 탭을 열고 명령을 실행해야합니다. 탭에는 제목을 구분해야합니다. 스크립트는 실행하지 않고 탭에 명령을 작성해야합니다.쉘 스크립트 : 새 그놈 터미널 탭의 제목 설정
스크립트에 입력 파일 start.txt가 필요합니다. 이 파일은 줄 단위로 처리됩니다. 각 줄에는 먼저 터미널 탭의 제목이 들어 있으며 쉼표로 구분됩니다.
매우 쉽게 그놈 터미널 호출 타이틀을 도시한다 :
그놈 터미널 - 탭 --title TEST1 = -e 가기 --tab --title = TEST2 가기
그러나 복잡한 명령을 사용하면이 기능이 작동하지 않고 제목이 설정되지 않습니다.
#!/bin/bash
# define variable which needs to be executed
cmdline="gnome-terminal"
# define input file
file="cat start.txt"
# define run_command script
destdir=/home/ank1abt/Documents/run_command.sh
# create if not already existing and change permissions
touch $destdir
chmod 755 $destdir
# read file an process line by line
# each line contains first the title and with comma separated the command for a new tab in a terminal
$file | \
while read row; do
#extract tab title and command
title=$(echo $row | awk -F"," '{print $1}')
cmd=$(echo $row | awk -F"," '{print $2}')
set_title="export PS1='\[\e]0;"$title"\a\]\${debian_chroot:+(\$debian_chroot)}\[email protected]\h:\w\$'"
#cmdline=$cmdline\ "--tab --title="$title" -e top"
cmdline=$cmdline\ "--tab --title="$title" -e \"bash -c \\\" echo "$title"; echo export PS1='\[\e]0;"$title"\a\]\\\${debian_chroot:+(\\\$debian_chroot)}\[email protected]\h:\w\$';echo "$cmd"; exec bash\\\"\""
echo $cmdline
# command will be written to a file
echo "$cmdline" > $destdir
done
# execute the file with the command
exec "./run_command.sh"
내가 해결 방법을 시도 한편 :
여기에 전체 코드입니다.
수출 PS1 '= 사용자가 복사하여 실행할 수 있도록 다음 탭에서 실행하거나 거기에 기록 할 수있는 탭 내에서 탭 타이틀을 설정할 수있는 또 다른 흥미로운 명령이 있습니다 [\ E] 0; 임무 \ A] $ {debian_chroot : + ($의 debian_chroot)} \ U @ H \ w $ '
그러나
현재 코드의 다음 명령 run_command 기록한다 \ 스크립트 :gnome-terminal --tab --title = test1 -e "bash -c \"echo test1; echo export PS1 = '[\ e] 0; test1 \ a] \ $ {debian_chroot : + (\ $ debian_chroot) \ u @ \ h : \ w $'; echo top; exec bash \ ""- tab --title = test2 -e "bash -c \"echo test2; echo export PS1 = '[\ e] 0; test2 \ a] \ $ {debian_chroot : + (\ $ debian_chroot) \ u h \ \ $$; echo top; exec bash \ ""
이 명령을 복사하여 터미널에서 실행하면 탭에 내보내기 명령이 표시되지만 작은 따옴표로 묶이지 않고 작동하지 않습니다.
수출 PS1 = [\ E] 0; 임무 \ A] $ {debian_chroot : + ($의 debian_chroot)} \ U @ H : \ 확인을 위해 $
내가 선호 승 \ gnome-terminal 명령의 title 옵션을 얻는다. 그러나 이것이 가능하지 않다면 나는 singe quotes의 탭에서 PS1을 내보내는 값을 갖는 방법에 대해 어떤 힌트도 기뻐할 것이다. 나는 이미 성공하지 않고 \ 또는 여러 개의 \로 이스케이프하려고 시도했다.