Não encontrei nenhuma opção para impedir a abertura de uma janela quando o Terminal é iniciado, mas você pode verificar se a sessão bash atual foi iniciada exatamente ao mesmo tempo em que o Terminal foi iniciado. Se esse for o caso, a sessão bash deve sair.
Você verá uma janela aparecendo e desaparecendo por uma fração de segundo.
Adicione o seguinte código (testado no Mac OS X 10.5.8 (Leopard) [ veja minha nota abaixo ] e no OS X 10.8.2 (Mountain Lion)) no início de seu ~/.bash_profile :
shell_started=$(ps -A -o lstart $$ | grep -v STARTED)
terminal_started=$(ps -A -o lstart $(ps -A -o pid -o command | grep '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn' | grep -v grep | cut -d '/' -f 1) | grep -v STARTED)
if [ "X$shell_started" == "X$terminal_started" ]; then exit; fi
Explicação do código:
shell_started=$(ps -A -o lstart $$ | grep -v STARTED) : executepsto print when process identifed by variable$$started ($$expands to the PID ot thisbashsession). Then filter out the header (which contains the wordSTARTED). Assign resulting value to variableshell_started.
ps -A -o pid -o command | grep '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn' | grep -v grep | cut -d '/' -f 1: executepsto print all process command names, select the one that matches the full path to Terminal, filter out any spuriousgrepprocesses and extract process ID withcut.
terminal_started=$(ps -A -o lstart $(...) | grep -v STARTED): executepsto print when process Terminal started, and filter out the header (which contains the wordSTARTED).(I had to create
terminal_startedin two steps to get rid of TABspsadded to the output.)
if [ "X$shell_started" == "X$terminal_started" ]; then exit; fi: Compare both dates and if equal, exit the shell, that is, close the Terminal window.
Se não estiver funcionando para você (como foi o caso do OP, que usa o Mac OS X 10.6.8 (Snow Leopard)), tente:
shell_started=$(ps -A -o lstart $$ | grep -v STARTED)
terminal_started=$(ps -A -o lstart $(ps -A -o pid -o command | grep '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn' | grep -v grep | tail -n 1| cut -d '/' -f 1) | grep -v STARTED)
if [ "X$shell_started" == "X$terminal_started" ]; then exit; fi
(A única diferença aqui é um tail in terminal_started que seleciona a última entrada impressa por ps , caso haja mais de um.)
Nota para o Mac OS X 10.5.8 (Leopard) :
No meu antigo PowerBook G4, notei que às vezes havia uma diferença de um segundo entre os horários de início do Terminal e a atual bash de sessão. Se você estiver com problemas semelhantes em um computador lento, adicione essas três linhas de linha ao final do código acima:
one_second_before=$(expr "$shell_started" : '.*:\([0-9][0-9]\) .*' - 1)
shell_started_one_second_before=$(echo $shell_started | sed 's/\(.*:\)\([0-9][0-9]\)\( .*\)/'$one_second_before'/')
if [ "X$shell_started_one_second_before" == "X$terminal_started" ]; then exit; fi
Existe uma condição de contorno em que este código não funciona bem, ou seja, quando o shell foi iniciado no segundo 0, mas eu não queria adicionar mais complexidade.