shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Ajuda Com Shell


From: Vinicius Ruiz
Subject: Re: [shell-script] Ajuda Com Shell
Date: Mon, 22 Oct 2018 14:22:39 +0000 (UTC)

 Olá Pere,
Dessa forma passando com variáveis fica bem simples também.
Obrigado pela sugestão...
Graciassss...
Abs..
Vinicius
    Em sábado, 20 de outubro de 2018 15:09:27 BRT, 'T.Collons' address@hidden 
[shell-script] <address@hidden> escreveu:  
 
     
 

Hola Vinicious
 

 
 
Te escribo en castellano, porque aquí en la lista ya me han dicho que no use a 
google para hacerlo en "brasileiro".
 
Ahora que he visto que has puesto de tu parte, te informo que con SED también 
puedes usar variables que puedes definir antes de ejecutar la substitución, te 
lo digo porque no creo que todas las substituciones vayan a ser para la misma 
fecha.
 
Imagino que "SEGUNDA_SEXTA_JANEIRO DESCRIPTION "SEGUNDA_SEXTA_JANEIRO" es una 
fecha o una hora, no se exactamente que significa, pero que ira cambiando en 
los distintos ficheros y tendrás que substituirlo por distintas fechas u horas, 
así que si creas un script, puedes escribir como parámetro la cadena a 
substituir y pasársela a SED.
 
SED quedaría así 
 
  
original="ON RUNCYCLE SEGUNDA_SEXTA_JANEIRO DESCRIPTION "SEGUNDA_SEXTA_JANEIRO"
 
TuSubstitucion="ON RUNCYCLE TODA_PRIMEIRA_QUARTA_JAN VALIDFROM 01/02/2019 
"FREQ=MONTHLY;INTERVAL=12;BYDAY=1WE""
 
echo $original |sed 's|ON RUNCYCLE.*$|'"$TuSubstitucion"'|'
 
 

 
 
 El 20/10/18 a les 01:30, Vinicius address@hidden [shell-script] ha escrit:
  
    Jonathan e Itamar 
 
  Obrigado pelas explicações e pela ajuda.
 
  Ficou claro aqui a interpretação.
 
  Grande abraço.
 
  Vinicius 
 
  Sent from BlueMail  On Oct 19, 2018, at 19:22, "address@hidden 
[shell-script]" <address@hidden> wrote: 
     Cara Vínicius   
   O Jonathan explicou bem o siginificado da estrutura no sed quando se usa a 
substituição.   Mas a sua abordagem anterior você se valeu do recurso do 
escape, ou como diria o mestre Julio, você usou a kriptonita na barra, tirando 
os poderes dela de ser o caractere separador.   
   na estrutura da substituição o primeiro caractere após o s é usado como o 
elemento separador das partes e nommalmente esse caractere é a barra simples, 
mas quando o texto a ser substituido tem barras em seu conteúdo, o sed pode 
confundir e interpretrar essa barra do texto como separador, entãi para que 
isso não ocorra escapamos, tiramos o poder da barra usando \/.   Como seu texto 
tinha datas que usavam barras, essas barras precisavam usar esse recurso nesse 
contexto mais comum.   Mas ao usar outro caractere logo após o s, no caso eu 
usei o pipe ( | ) e o Jonathan sugeriu a cerquilha ( # ), trocamos o caractere 
separador, e então não há a necessidade de escapar nessa segundo caso. E 
poderia ser qualquer caractere além do pipe ou cerquilha, como uma vírgula ( , 
), arroba ( @ ), undercore ( _ ), ou até uma letra comum ou até mesmo um 
espaço. O importante é escolher um caractere que não esteja no texto a ser 
substituído, senão haverá a necessidade de escapar esse caractere.   
   Não sei se fui claro, mas essa é a idéia   
   []'s   Itamar 
   
   
 
 -- 
 

 
 
 
Pere
 
address@hidden
 

 
 
 
  
 
 
------------------------------------
 
AVIS LEGAL
 
 Nota de confidencialitat: Aquest missatge podria contenir missatges d'empresa 
i altre informació confidencial tutelada per les lleis de Europea i altres 
estats, Si Vostè el rep per error o sense ser una de les persones esmenades a 
la capçalera, haurà de destruir-lo sense copiar-lo ni revelar-l'ho o qualsevol 
altre acció relacionada amb el contingut del missatge i notificar-ho per correu 
electrònic a l'emissor del missatge.  
  
Les persones o entitats que incompleixin els deures de confidencialitat podran 
ésser perseguides davant dels Tribunals de Justícia sota l'empar de la 
legislació civil, penal i administrativa nacional i internacional.    
 
Gracies per la seva cooperació.
 
------------------------------------
 
LEGAL NOTICE
 
Confidentiality notice: This mail may include business and other confidential 
information protected under the laws of and other territories. if you are not 
one of the intended recipients of the message, you are legally obliged to 
delete the message content. Furthermore, you are kindly requested to report 
immediately the incident to the sender.  
  
Breach of confidentiality duties is a serious criminal offence in and other 
territories. Offenders shall be legally prosecuted worldwide.   
 
Thank you for your cooperation.
 

 
 
 #yiv6676206990 #yiv6676206990 -- #yiv6676206990ygrp-mkp {border:1px solid 
#d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv6676206990 
#yiv6676206990ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv6676206990 
#yiv6676206990ygrp-mkp #yiv6676206990hd 
{color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 
0;}#yiv6676206990 #yiv6676206990ygrp-mkp #yiv6676206990ads 
{margin-bottom:10px;}#yiv6676206990 #yiv6676206990ygrp-mkp .yiv6676206990ad 
{padding:0 0;}#yiv6676206990 #yiv6676206990ygrp-mkp .yiv6676206990ad p 
{margin:0;}#yiv6676206990 #yiv6676206990ygrp-mkp .yiv6676206990ad a 
{color:#0000ff;text-decoration:none;}#yiv6676206990 #yiv6676206990ygrp-sponsor 
#yiv6676206990ygrp-lc {font-family:Arial;}#yiv6676206990 
#yiv6676206990ygrp-sponsor #yiv6676206990ygrp-lc #yiv6676206990hd {margin:10px 
0px;font-weight:700;font-size:78%;line-height:122%;}#yiv6676206990 
#yiv6676206990ygrp-sponsor #yiv6676206990ygrp-lc .yiv6676206990ad 
{margin-bottom:10px;padding:0 0;}#yiv6676206990 #yiv6676206990actions 
{font-family:Verdana;font-size:11px;padding:10px 0;}#yiv6676206990 
#yiv6676206990activity 
{background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv6676206990
 #yiv6676206990activity span {font-weight:700;}#yiv6676206990 
#yiv6676206990activity span:first-child 
{text-transform:uppercase;}#yiv6676206990 #yiv6676206990activity span a 
{color:#5085b6;text-decoration:none;}#yiv6676206990 #yiv6676206990activity span 
span {color:#ff7900;}#yiv6676206990 #yiv6676206990activity span 
.yiv6676206990underline {text-decoration:underline;}#yiv6676206990 
.yiv6676206990attach 
{clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 
0;width:400px;}#yiv6676206990 .yiv6676206990attach div a 
{text-decoration:none;}#yiv6676206990 .yiv6676206990attach img 
{border:none;padding-right:5px;}#yiv6676206990 .yiv6676206990attach label 
{display:block;margin-bottom:5px;}#yiv6676206990 .yiv6676206990attach label a 
{text-decoration:none;}#yiv6676206990 blockquote {margin:0 0 0 
4px;}#yiv6676206990 .yiv6676206990bold 
{font-family:Arial;font-size:13px;font-weight:700;}#yiv6676206990 
.yiv6676206990bold a {text-decoration:none;}#yiv6676206990 dd.yiv6676206990last 
p a {font-family:Verdana;font-weight:700;}#yiv6676206990 dd.yiv6676206990last p 
span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv6676206990 
dd.yiv6676206990last p span.yiv6676206990yshortcuts 
{margin-right:0;}#yiv6676206990 div.yiv6676206990attach-table div div a 
{text-decoration:none;}#yiv6676206990 div.yiv6676206990attach-table 
{width:400px;}#yiv6676206990 div.yiv6676206990file-title a, #yiv6676206990 
div.yiv6676206990file-title a:active, #yiv6676206990 
div.yiv6676206990file-title a:hover, #yiv6676206990 div.yiv6676206990file-title 
a:visited {text-decoration:none;}#yiv6676206990 div.yiv6676206990photo-title a, 
#yiv6676206990 div.yiv6676206990photo-title a:active, #yiv6676206990 
div.yiv6676206990photo-title a:hover, #yiv6676206990 
div.yiv6676206990photo-title a:visited {text-decoration:none;}#yiv6676206990 
div#yiv6676206990ygrp-mlmsg #yiv6676206990ygrp-msg p a 
span.yiv6676206990yshortcuts 
{font-family:Verdana;font-size:10px;font-weight:normal;}#yiv6676206990 
.yiv6676206990green {color:#628c2a;}#yiv6676206990 .yiv6676206990MsoNormal 
{margin:0 0 0 0;}#yiv6676206990 o {font-size:0;}#yiv6676206990 
#yiv6676206990photos div {float:left;width:72px;}#yiv6676206990 
#yiv6676206990photos div div {border:1px solid 
#666666;min-height:62px;overflow:hidden;width:62px;}#yiv6676206990 
#yiv6676206990photos div label 
{color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv6676206990
 #yiv6676206990reco-category {font-size:77%;}#yiv6676206990 
#yiv6676206990reco-desc {font-size:77%;}#yiv6676206990 .yiv6676206990replbq 
{margin:4px;}#yiv6676206990 #yiv6676206990ygrp-actbar div a:first-child 
{margin-right:2px;padding-right:5px;}#yiv6676206990 #yiv6676206990ygrp-mlmsg 
{font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv6676206990 
#yiv6676206990ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv6676206990 
#yiv6676206990ygrp-mlmsg select, #yiv6676206990 input, #yiv6676206990 textarea 
{font:99% Arial, Helvetica, clean, sans-serif;}#yiv6676206990 
#yiv6676206990ygrp-mlmsg pre, #yiv6676206990 code {font:115% 
monospace;}#yiv6676206990 #yiv6676206990ygrp-mlmsg * 
{line-height:1.22em;}#yiv6676206990 #yiv6676206990ygrp-mlmsg #yiv6676206990logo 
{padding-bottom:10px;}#yiv6676206990 #yiv6676206990ygrp-msg p a 
{font-family:Verdana;}#yiv6676206990 #yiv6676206990ygrp-msg 
p#yiv6676206990attach-count span {color:#1E66AE;font-weight:700;}#yiv6676206990 
#yiv6676206990ygrp-reco #yiv6676206990reco-head 
{color:#ff7900;font-weight:700;}#yiv6676206990 #yiv6676206990ygrp-reco 
{margin-bottom:20px;padding:0px;}#yiv6676206990 #yiv6676206990ygrp-sponsor 
#yiv6676206990ov li a {font-size:130%;text-decoration:none;}#yiv6676206990 
#yiv6676206990ygrp-sponsor #yiv6676206990ov li 
{font-size:77%;list-style-type:square;padding:6px 0;}#yiv6676206990 
#yiv6676206990ygrp-sponsor #yiv6676206990ov ul {margin:0;padding:0 0 0 
8px;}#yiv6676206990 #yiv6676206990ygrp-text 
{font-family:Georgia;}#yiv6676206990 #yiv6676206990ygrp-text p {margin:0 0 1em 
0;}#yiv6676206990 #yiv6676206990ygrp-text tt {font-size:120%;}#yiv6676206990 
#yiv6676206990ygrp-vital ul li:last-child {border-right:none 
!important;}#yiv6676206990   

[As partes desta mensagem que não continham texto foram removidas]


From address@hidden Wed Oct 24 07:26:57 2018
Return-Path: <address@hidden>
X-Sender: address@hidden
X-Apparently-To: address@hidden
X-Received: (qmail 36661 invoked by uid 102); 24 Oct 2018 14:26:57 -0000
X-Received: from unknown (HELO mtaq2.grp.bf1.yahoo.com) (10.201.224.240)
  by m14.grp.bf1.yahoo.com with SMTP; 24 Oct 2018 14:26:57 -0000
X-Received: (qmail 13522 invoked from network); 24 Oct 2018 14:26:56 -0000
X-Received: from unknown (HELO mta4004.groups.mail.ne1.yahoo.com) 
(10.218.140.75)
  by mtaq2.grp.bf1.yahoo.com with SMTP; 24 Oct 2018 14:26:56 -0000
X-Original-Return-Path: <address@hidden>
X-Received-SPF: pass (domain of gmail.com designates 209.85.166.45 as permitted 
sender)
X-YMailISG: cQUehOMWLDu30iuxebRKkIVQaxqcBFudyZrTieyyOQaF6JjS
 zMB1VMneXTPCAuCS3jZhpGc1gPdhdtYTSrJ_b2U68HjQ6u6tzcTFL76AiiY4
 OOjrXy6D54_hCWa0c4_w7e1lSPGTvUoMAVzrfBSFqozteLT7NFA.E_tAVOtC
 AFPnOWVbT1GPNWN.YGITkvsw68liKbJnM7ic2Xe6iVrPnHa8RxO97gc9wxiq
 bL2GJP7bxqX6bJIhqfdvveCmyfk2UZhBkn8D09idfYDmm9bNp4_2gdmE3che
 rDLIc8YLFWHoT6Qd0SfTxlZi8V5f5nPfq1vuRZFt2X6B3pYiM1Bnl6MBQLmu
 K60dbWn8dsqKl8tjH47hOlpmtnGYUjhJsGFCHJXPPNWXszCCftRq0.wwlSMs
 f4frmRnVtwvitEfiQopShSoaesrLbR14IZZDb_2i5epH7esrvQ3yFDvNqKvA
 82.DAsnaesra4jty5PFPo2vvKYSdFPhmcyEQUBfFsXuQF18NWV1XC1HDW8Pq
 l9_LrWpu3X4xzONSDBkPYkpXkDoKXmnwz5UXdR8ejyjHcLY2JXYU8Uco7D3f
 7Z_MfrrN9bXyyWX5u3s8W28Dio444tjUg_KSArrPfYJRaE8ImdeA.qehU3w7
 1CKrtfmX4lOVnNH_ultbgwvlfWjLOUL8w_ncXzlHyRtsBiOPZfcghUb.FJFa
 _5iCxiJIL9zgiSqRQLaNzPjVXhUxzkTGxU6zxiVfHOJvE6BYJ9uIyeMhIbAx
 n7l3e3q7E0sCcieHCRdC5MeSsbWHkmJqWr_ulTVrX25DOV0wk7MGjpfEwCaX
 EaV0IXpkPj99wMQalz0NRZ4zWhb_Af.MEmWIXD_sVtCWLiibBuZEsBzEqXsn
 56j2FX5A.qp7g.aIY6206p790ktYT3aNuSMzZe5brc5DE2vRWnme2s_nrjKd
 KqoVNEa9Fj4zL.flJFbDWPFurM7SdS0o2WQQoLAb6c6Y8pA3iv_QtaF6ydq_
 HUKp18UaAigIlEnZc7e5_ci7yua2eIhBFu0EBQ_k9gN45raGpUL78f6lDDVK
 9.7DYXVp28zPoJ4wSKG5KW_5vQ--
Authentication-Results: mta4004.groups.mail.ne1.yahoo.com  from=gmail.com; 
domainkeys=neutral (no sig);  from=gmail.com; dkim=pass (ok)
X-Received: from 127.0.0.1  (EHLO mail-io1-f45.google.com) (209.85.166.45)
  by mta4004.groups.mail.ne1.yahoo.com with SMTPS; Wed, 24 Oct 2018 14:26:56 
+0000
X-Received: by mail-io1-f45.google.com with SMTP id n18-v6so3254261ioa.9
        for <address@hidden>; Wed, 24 Oct 2018 07:26:56 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d100.net; s 161025;
        h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
        bh
GZwFChFh9UDHmBcR9KGk5jMKgUKB7g8ViBYH2APwY=;
        b�qXAIIsuiLzwKV+ZfS/WlHzoHWhF5wTrY1051TLlL/VwHk+ultUW2T0jZPCLARZn5
         kTgw7JlmfbuIG5D9+71HBH+GGmJj+TiA7U92JZ6ZGTgwMgT+JlvQ1K2bxXQRZCoatMmK
         TBe5pFgdKk6fEQoCWLhZTteA6ibprEQzwMODlpDZRDwsJRh96MGIf8YFNFRXzjz5mNer
         xJO9Mrxbbts9TyGTb+ITEgvmGCAYzDYTNZt9DrSjgQywo7ryunIY3G+lfyYSAlbM8JxD
         7UgBeP3NptbwrkzBacRWVEjLzRYMEjyGr0nQo/vVDKybHjXCW5WDaGSGleuAlVb2LKgK
         mzXw=X-Gm-Message-State: 
AGRZ1gJfjKeXaaqyVhssbWpPKaxZN9F8ui3vgMqLY5K21sxyHFmbQ3Ug
        iR69rTO0LA/7q1ozCT8z1SCFrIMVj+jSDcgY6Rr0JdHc
X-Google-Smtp-Source: 
AJdET5fBI5d+9+VpzcgHNyYYoGlERq5nhBxJ7dateBlupG3gRPv0gecPxaECkJl+bjpQvM5n8/uQpc4zXUU9v8mxdeAX-Received:
 by 2002:a6b:d112:: with SMTP id l18-v6mr14176506iob.146.1540391215525;
 Wed, 24 Oct 2018 07:26:55 -0700 (PDT)
MIME-Version: 1.0
Date: Wed, 24 Oct 2018 11:26:44 -0300
Message-ID: <CACixCcb9o7pq0cNEREg=b=address@hidden>
To: address@hidden
Content-Type: multipart/alternative; boundary="000000000000377ac70578fa47b8"
X-Originating-IP: 10.218.140.75
Subject: Array mais lento do que "-f $aquivo"
X-Yahoo-Group-Post: member; u27267252; 
y=1pzim8b9kxisxA7oSQWCvhdpOl-MIXk84fIkWHJ0zAujRECt
X-Yahoo-Profile: eribastos
From: Eri Ramos Bastos <address@hidden>

--000000000000377ac70578fa47b8
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Olá, lista!

Tenho um script que roda a seguinte função ~300 vezes (sourced de outro
arquivo):

check_role() {
if [ -d /etc/roles/ ]; then
if [ -f /etc/roles/$1 ]; then
return 0
fi
fi
return 1
}

Pensei que iria ganhar performance fazendo isso:

list_roles() {
if [ -d /etc/roles/ ]; then
cd /etc/roles
ls
else
echo ""
fi

}

export ROLES=($(list_roles))
check_role() {
local role=$1
for r in "${ROLES[@]}"; do
[[ "$r" == "$role" ]] && return 0
done
return 1

}

Mas na verdade o tempo de execução piorou:

Original:
real    0m2.069s
user    0m0.300s
sys     0m1.644s

Novo:
real    0m2.857s
user    0m0.348s
sys     0m2.296s


Me parece contra-intuitivo, já que o original precisa checar em disco todas
as vezes. Onde estou errado?

Obrigado!

--000000000000377ac70578fa47b8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Olá, 
lista!<div><br></div><div>Tenho um script que roda a seguinte função ~300 vezes 
(sourced de outro arquivo):</div><div><br></div><div><div><font 
face="monospace, monospace" size="1">check_role() {</font></div><div><font 
face="monospace, monospace" size="1"><span style="white-space:pre"> </span>if [ 
-d /etc/roles/ ]; then<br></font></div><div><font face="monospace, monospace" 
size="1"><span style="white-space:pre">               </span>if [ -f 
/etc/roles/$1 ]; then</font></div><div><font face="monospace, monospace" 
size="1"><span style="white-space:pre">                 </span>return 
0</font></div><div><font face="monospace, monospace" size="1"><span 
style="white-space:pre">              </span>fi</font></div><div><font 
face="monospace, monospace" size="1"><span style="white-space:pre">    
</span>fi</font></div><div><font face="monospace, monospace" size="1"><span 
style="white-space:pre">    </span>return 1</font></div><div><font 
face="monospace, monospace" 
size="1">}</font></div></div><div><br></div><div>Pensei que iria ganhar 
performance fazendo isso:</div><div><br></div><div><div><font size="1" 
face="monospace, monospace">list_roles() {</font></div><div><font size="1" 
face="monospace, monospace"><span style="white-space:pre"> </span>if [ -d 
/etc/roles/ ]; then</font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre">           </span>cd 
/etc/roles</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre">         </span>ls</font></div><div><font size="1" 
face="monospace, monospace"><span style="white-space:pre">    
</span>else</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre">          </span>echo 
&quot;&quot;</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre">     </span>fi</font></div><div><font size="1" 
face="monospace, monospace"><br></font></div><div><font size="1" 
face="monospace, monospace">}</font></div><div><font size="1" face="monospace, 
monospace"><br></font></div><div><font size="1" face="monospace, 
monospace">export ROLES=($(list_roles))</font></div></div><div><div><font 
size="1" face="monospace, monospace">check_role() {</font></div><div><font 
size="1" face="monospace, monospace"><span style="white-space:pre">     
</span>local role=$1<br></font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre">     </span>for r in 
&quot;${ROLES[@]}&quot;; do</font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre">          </span>[[ &quot;$r&quot; == 
&quot;$role&quot; ]] &amp;&amp; return 0</font></div><div><font size="1" 
face="monospace, monospace"><span style="white-space:pre"> 
</span>done</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre">  </span>return 1</font></div><div><font size="1" 
face="monospace, monospace"><br></font></div><div><font size="1" 
face="monospace, monospace">}</font></div></div><div><br></div><div>Mas na 
verdade o tempo de execução 
piorou:</div><div><br></div><div>Original:</div><div><span 
style="font-family:monospace">real    0m2.069s </span><br 
style="font-family:monospace"><span style="font-family:monospace">user    
0m0.300s </span><br style="font-family:monospace"><span 
style="font-family:monospace">sys     0m1.644s</span><span 
style="font-family:monospace"><br></span></div><div><span 
style="font-family:monospace"><br></span></div><div><font face="arial, 
helvetica, sans-serif">Novo:<br></font><font face="monospace">real    0m2.857s
</font><br><font face="monospace">user    0m0.348s
</font><br><font face="monospace">sys     0m2.296s
</font><br><br><br>
<font face="arial, helvetica, sans-serif">Me parece contra-intuitivo, já que o 
original precisa checar em disco todas as vezes. Onde estou 
errado?</font></div><div><font face="arial, helvetica, 
sans-serif"><br></font></div><div><font face="arial, helvetica, 
sans-serif">Obrigado!</font></div><div><br></div></div></div></div></div>

--000000000000377ac70578fa47b8--

From address@hidden Wed Oct 24 08:17:39 2018
Return-Path: <address@hidden>
X-Sender: address@hidden
X-Apparently-To: address@hidden
X-Received: (qmail 22400 invoked by uid 102); 24 Oct 2018 15:17:39 -0000
X-Received: from unknown (HELO mtaq1.grp.bf1.yahoo.com) (10.201.224.239)
  by m10.grp.bf1.yahoo.com with SMTP; 24 Oct 2018 15:17:39 -0000
X-Received: (qmail 15223 invoked from network); 24 Oct 2018 15:17:38 -0000
X-Received: from unknown (HELO mta4004.groups.mail.ne1.yahoo.com) 
(10.218.140.75)
  by mtaq1.grp.bf1.yahoo.com with SMTP; 24 Oct 2018 15:17:38 -0000
X-Original-Return-Path: <address@hidden>
X-Received-SPF: pass (domain of gmail.com designates 209.85.222.175 as 
permitted sender)
X-YMailISG: cWOXFygWLDtm4cTvL4VMXlgQXBIvZakCydD7tGH.CUEXHJy5
 AyrIyHDqD5qgSFErpbmIqOvucXTMLxvdBDJ9QTGCe8jxzLX.Xrumg76RaiiM
 WqubwKPwrQA_kCfzJfC0aBITZuY1GpB_cD9vgmx3aGK91doXncxNY7Vcy5je
 lw_qwjfEuv9b5bsjCReZI6eNtasuTchWVsaU9QgPjcU1TaBoxBoN6gpE0wnP
 figa.kVLXe4ud7JhSxecXUfgXpn4a_Zu9n0mjqpxnqL6MlO3RF2wjB1WypMH
 uvAQ1zUbW92u562W6avB3Evw8fCb6iEPHkPzWaU_.gVheGdaNzo2x1Pti29e
 z49LRJ2IH1vcu42JZxfr6O89iZBNgmZ.pNBDk7gzCutrtslzUEdamSQaIHtB
 wsCZz6YfEoQFAxeH28mfvkX3PPmJx_JGMpT1lH43w0RmgtGFO8ZobgUodJVi
 6CNaO8vUu8KOmKxSTxddrjGeFNUQnr5JaR9.E14bdhsXXjg_VKJue2fjCfsC
 9VFAhPWrQNGtwvfir5xFjqHcDJ7pV2dgE.bFGSYmyyURWxXtU2Xd4oTbHeoe
 S_FTMtfRaZm1Cy5dMpT4Qk2yU77LBJkJ7by7bZN_nhUjEZ1k_dIgVCVpnMhZ
 69h8Yq98Ke0iKbqH0NZpwyX3HTw1YcCJFXBVFa8xgI0IxUEjezwc15pWbx6Y
 B1URskNNUbuiIcwRqu5jlpY3q0UCeqB4_743ftTkvbhLtZMWtoVMXJucjgkJ
 anVxO8aEIr8UDdQhN.lApbCZWHtYoTwo3mcnHPHGPAyyj4pmlmJrLoLLzFl8
 JjEC8330DfNP93ulORyPqZKAb7ZFyiYnzF9rNVZFCpHcutaFBwIwsZE09Iff
 HMZkXgJrjZiTzb6PS5wZZMjW5jTNC99VYficQHyt09bmBBBoCRyuVU0ebJ.3
 RzQwa1JV7Eo.J10bJN.iRZX6gJuD9BRVD1LcvMKZ0BRA2dePowPJ86_kii8J
 .BzirSZRyLda8Ot3C7C13x.9NyQWRlLM5Ie040YrC98E.qGCfeVJUkMW_2rd
 hJ1JxXDkfHNBnrZzkcNVK2Fvvn2bwmtv6HGL2HaGcNFVv9wrK5BjtNOhI8Tv
 CFFa0hWVkdY5janeOBo0.KWrCUoGUyNorl4yJ0sR_JbZ8LTaJzCyj2sNbXrr
 PHnduGrxHzm9HloBjQp7kzZQps5ELjbw4gs4gwxQDMgkhOVFM5K5lwZguboT
 zmBDNwYbbLlA8jZqNaL663mb17m51WgvGY..l4iVBktoZtiCyXRfIOA.LjSw
 O6wGAEZCYIiX4KufMJ9VdN5wBcrHU1Et8_H900bZVyNTNNJ_ncg1BMaLm7mR
 KkMF86zDxJTbgPLeMjt.ypgZFGVHgWiXJHWLH6Oj2S0033YLwm6Inz3Q3CXE
 u7P4k2N7lBYaJs4Y4ap2ObXAXpULzDg3ef26KSgLY2JJGdSAtINHvTamx2jW
 39qUNun8rXhg.rwSR603Dw--
Authentication-Results: mta4004.groups.mail.ne1.yahoo.com  from=gmail.com; 
domainkeys=neutral (no sig);  from=gmail.com; dkim=pass (ok)
X-Received: from 127.0.0.1  (EHLO mail-qk1-f175.google.com) (209.85.222.175)
  by mta4004.groups.mail.ne1.yahoo.com with SMTPS; Wed, 24 Oct 2018 15:17:36 
+0000
X-Received: by mail-qk1-f175.google.com with SMTP id v68-v6so3594079qka.2
        for <address@hidden>; Wed, 24 Oct 2018 08:17:36 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d100.net; s 161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to;
        bh-KvCgwk2dj2U7TQm8g5nnQGm1zQ0x72abMQDai1eQo=;
        b=Bn6Qgq5kCTF1Dc7XuMgXkA1zk2zC1OjR9zuJaM7Njbg1V2oN/yb20Y9F0WyBv1RFPO
         NJW1yiflVAX87ZSpV5q3C3ITi/TBy6c9C7QXVH2OUatyMjHZZO7fg6EsqC2x4R7VNsZU
         65thDKBMXoZmPnoy0x3TqIcS3xigbFScjdLkdIyeTtRB5u2/oIDXQFzhcF3J62TrBOks
         pPRZLlAF8zw1QiOFgWhIf7qwnraBUmEsOs+ln3raIa9y71zkZJLPjA3qCoeSZq/Tf7k+
         aCsVoLXzDOit1EpU5Ev5uyyXl6pmF+YVZz6dsnrFX52Sk7zMwFtwCUvPcif2lr3VfOqc
         6PGw=X-Gm-Message-State: 
AGRZ1gIaFU7tgVC5ppJ9/D2COEOS14U6JYWNeEc12vscke6HHrJRdb7X
        /ZkBx9TA4FaVmKA2FsHZRgQvSR0Pgc64xZ5lQTsF0sju
X-Google-Smtp-Source: 
AJdET5c0XAz+I3afw+ZuLqDODy/369YHfUplv92F5anTGJT7xHSwnnSFt1gDGx5l7tWCarpc0zDmaDHKzgNb0yWS6bMX-Received:
 by 2002:a37:bd05:: with SMTP id n5-v6mr2737481qkf.204.1540393761572;
 Wed, 24 Oct 2018 08:09:21 -0700 (PDT)
MIME-Version: 1.0
References: <CACixCcb9o7pq0cNEREg=b=address@hidden>
In-Reply-To: <CACixCcb9o7pq0cNEREg=b=address@hidden>
Date: Wed, 24 Oct 2018 12:08:44 -0300
Message-ID: <CAJ=pi6k5LV8u-jT+P=address@hidden>
To: address@hidden
Content-Type: multipart/alternative; boundary="000000000000f90a550578fade1c"
X-Originating-IP: 10.218.140.75
Subject: Re: [shell-script] Array mais lento do que "-f $aquivo"
X-Yahoo-Group-Post: member; u"5776457; 
y=ELjslpUalPSoKhybVwVdcw09GJyuam8zjKQApEuJWjUGo2Qel4Ru
X-Yahoo-Profile: julioneves99
From: "Julio C. Neves" <address@hidden>

--000000000000f90a550578fade1c
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Fala Eri
Acho vc ganharia performance se fizesse:

check_role() {
local ROLES=($(ls /etc/roles)) || return 1
for r in "${ROLES[@]}"; do
[[ "$r" == "$1" ]] && return 0
done
}

Abraços,
Julio

*» Não tem tempo para fazer um curso presencial?*
*» Na sua cidade não tem nenhum bom curso de Linux?*
*» **Conheça nosso portal educacional e estude conosco: *
*     http://www.dicas-l.com.br/educacao
<http://www.dicas-l.com.br/educacao/>*
*»  Treinamento presencial (em 4 sábados) no RJ e BSB *
*    em http://bit.ly/cursoshelljulioneves
<http://bit.ly/cursoshelljulioneves>                   *



*Também damos treinamento em sua empresa*
*em qualquer cidade**, **com certificado **e nota fiscal.*



Em qua, 24 de out de 2018 às 11:41, Eri Ramos Bastos address@hidden
[shell-script] <address@hidden> escreveu:

>
>
> Olá, lista!
>
> Tenho um script que roda a seguinte função ~300 vezes (sourced de outro
> arquivo):
>
> check_role() {
> if [ -d /etc/roles/ ]; then
> if [ -f /etc/roles/$1 ]; then
> return 0
> fi
> fi
> return 1
> }
>
> Pensei que iria ganhar performance fazendo isso:
>
> list_roles() {
> if [ -d /etc/roles/ ]; then
> cd /etc/roles
> ls
> else
> echo ""
> fi
>
> }
>
> export ROLES=($(list_roles))
> check_role() {
> local role=$1
> for r in "${ROLES[@]}"; do
> [[ "$r" == "$role" ]] && return 0
> done
> return 1
>
> }
>
> Mas na verdade o tempo de execução piorou:
>
> Original:
> real    0m2.069s
> user    0m0.300s
> sys     0m1.644s
>
> Novo:
> real    0m2.857s
> user    0m0.348s
> sys     0m2.296s
>
>
> Me parece contra-intuitivo, já que o original precisa checar em disco
> todas as vezes. Onde estou errado?
>
> Obrigado!
>
> 
>

--000000000000f90a550578fade1c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir="ltr"><div dir="ltr"><div class="gmail_default" 
style="font-family:monospace,monospace">Fala Eri</div><div 
class="gmail_default" style="font-family:monospace,monospace">Acho vc ganharia 
performance se fizesse:</div><div class="gmail_default" 
style="font-family:monospace,monospace"><br></div><div 
class="gmail_default"><div class="gmail_default"><font face="monospace, 
monospace">check_role() {</font></div><div class="gmail_default"><font 
face="monospace, monospace"><span style="white-space:pre">     </span>local 
ROLES=($(ls /etc/roles)) || return 1</font></div><div 
class="gmail_default"><font face="monospace, monospace"><span 
style="white-space:pre">       </span>for r in &quot;${ROLES[@]}&quot;; 
do</font></div><div class="gmail_default"><font face="monospace, 
monospace"><span style="white-space:pre">             </span>[[ &quot;$r&quot; 
== &quot;$1&quot; ]] &amp;&amp; return 0</font></div><div 
class="gmail_default"><font face="monospace, monospace"><span 
style="white-space:pre">       </span>done</font></div><div 
class="gmail_default"><font face="monospace, monospace">}</font></div><div 
class="gmail_default"><font face="monospace, 
monospace"><br></font></div></div><div><div dir="ltr" 
class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div 
dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div><div><div style="font-size:small">Abraços,</div></div><div 
style="font-size:small">Julio</div><div style="font-size:small"><br></div><div 
style="font-size:small"><font face="monospace, monospace"><b>» Não tem tempo 
para fazer um curso presencial?</b></font></div><div 
style="font-size:small"><font face="monospace, monospace"><b>» Na sua cidade 
não tem nenhum bom curso de Linux?</b></font></div><div><font face="monospace, 
monospace" style="font-size:small"><b>» </b></font><b><font face="trebuchet ms, 
sans-serif" style="font-size:12.8px">Conheça nosso portal educacional e estude 
conosco: </font></b></div><div><b><font face="trebuchet ms, sans-serif" 
style="font-size:12.8px">     h</font><span 
style="font-size:12.8px;font-family:&quot;trebuchet 
ms&quot;,sans-serif">ttp://<a href="http://www.dicas-l.com.br/educacao/"; 
style="color:rgb(17,85,204)" 
target="_blank">www.dicas-l.com.br/educacao</a></span></b></div><div><b>»  
Treinamento presencial (<font color="#660000" 
style="background-color:rgb(255,229,153)">em 4 sábados</font>) no RJ e BSB 
</b></div><div><b>    em <a href="http://bit.ly/cursoshelljulioneves"; 
style="color:rgb(17,85,204);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px"
 target="_blank">http://bit.ly/cursoshelljulioneves</a>                   
</b><img src="http://www.sindepolpb.com.br/novo3.gif"; style="font-size: 
12.8px;"></div><div style="font-size:small"><br></div></div><div 
style="font-size:small"><img 
src="https://docs.google.com/uc?export=download&amp;id=1ht9llgh0CjQlapOqFtxVcSRCcopbeHYc&amp;revid=0B6Rg1uyhMVcbaVpnR2xqaXhpQ094RnNMYkZUeWhQZVZvdzFzPQ";
 width="420" height="48"><br></div><div><div style="font-size:12.8px"><span 
style="font-size:small;font-family:monospace,monospace"><font 
color="#000000"><b><br></b></font></span></div><div 
style="font-size:12.8px"><span 
style="font-size:small;font-family:monospace,monospace"><font 
color="#000000"><b>Também damos treinamento em sua 
empresa</b></font></span></div><div style="font-size:12.8px"><b 
style="font-size:12.8px"><font color="#660000" 
style="background-color:rgb(255,229,153)">em qualquer cidade</font></b><b 
style="font-size:12.8px;color:rgb(0,0,0)"><span 
style="font-family:monospace,monospace"><span style="font-size:small">, 
</span></span></b><b style="font-size:12.8px;color:rgb(0,0,0)"><span 
style="font-family:monospace,monospace"><span style="font-size:small">com 
certificado </span></span></b><b 
style="font-size:12.8px;color:rgb(0,0,0)"><span 
style="font-family:monospace,monospace"><span style="font-size:small">e nota 
fiscal.</span></span></b></div></div><div style="font-size:12.8px"><b 
style="color:rgb(0,0,0);font-size:12.8px"><span 
style="font-family:monospace,monospace"><span 
style="font-size:small"><br></span></span></b></div><div><div 
style="font-size:12.8px"><div style="font-size:small"><div 
style="font-family:monospace,monospace;display:inline"><font face="Bitstream 
Vera Sans, sans-serif"><font 
style="font-size:11pt"></font></font></div></div></div></div><div><blockquote 
style="font-family:arial;font-size:small;margin:0px 0px 0px 
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div 
bgcolor="#FFFFFF"><blockquote><div 
dir="ltr"></div></blockquote></div></blockquote></div>


<p style="margin-bottom:0cm"></p><div>
<p></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div
 class="gmail_quote"><div dir="ltr">Em qua, 24 de out de 2018 às 11:41, Eri 
Ramos Bastos <a href="mailto:address@hidden";>address@hidden</a> [shell-script] 
&lt;<a href="mailto:address@hidden";>address@hidden</a>&gt; 
escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 
.8ex;border-left:1px #ccc solid;padding-left:1ex">


<u></u>









 
<div style="background-color:#fff">
<span style="display:none"> </span>


<div id="m_-8880873497147591167ygrp-mlmsg">
  <div id="m_-8880873497147591167ygrp-msg">


    <div id="m_-8880873497147591167ygrp-text">
      
      
      <p><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Olá, 
lista!<div><br></div><div>Tenho um script que roda a seguinte função ~300 vezes 
(sourced de outro arquivo):</div><div><br></div><div><div><font 
face="monospace, monospace" size="1">check_role() {</font></div><div><font 
face="monospace, monospace" size="1"><span style="white-space:pre-wrap">   
</span>if [ -d /etc/roles/ ]; then<br></font></div><div><font face="monospace, 
monospace" size="1"><span style="white-space:pre-wrap">          </span>if [ -f 
/etc/roles/$1 ]; then</font></div><div><font face="monospace, monospace" 
size="1"><span style="white-space:pre-wrap">                    </span>return 
0</font></div><div><font face="monospace, monospace" size="1"><span 
style="white-space:pre-wrap">         </span>fi</font></div><div><font 
face="monospace, monospace" size="1"><span style="white-space:pre-wrap">       
</span>fi</font></div><div><font face="monospace, monospace" size="1"><span 
style="white-space:pre-wrap">       </span>return 1</font></div><div><font 
face="monospace, monospace" 
size="1">}</font></div></div><div><br></div><div>Pensei que iria ganhar 
performance fazendo isso:</div><div><br></div><div><div><font size="1" 
face="monospace, monospace">list_roles() {</font></div><div><font size="1" 
face="monospace, monospace"><span style="white-space:pre-wrap">    </span>if [ 
-d /etc/roles/ ]; then</font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre-wrap">              </span>cd 
/etc/roles</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">            </span>ls</font></div><div><font 
size="1" face="monospace, monospace"><span style="white-space:pre-wrap">       
</span>else</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">             </span>echo 
&quot;&quot;</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">        </span>fi</font></div><div><font size="1" 
face="monospace, monospace"><br></font></div><div><font size="1" 
face="monospace, monospace">}</font></div><div><font size="1" face="monospace, 
monospace"><br></font></div><div><font size="1" face="monospace, 
monospace">export ROLES=($(list_roles))</font></div></div><div><div><font 
size="1" face="monospace, monospace">check_role() {</font></div><div><font 
size="1" face="monospace, monospace"><span style="white-space:pre-wrap">        
</span>local role=$1<br></font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre-wrap">        </span>for r in 
&quot;${ROLES[@]}&quot;; do</font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre-wrap">             </span>[[ 
&quot;$r&quot; == &quot;$role&quot; ]] &amp;&amp; return 
0</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">    </span>done</font></div><div><font size="1" 
face="monospace, monospace"><span style="white-space:pre-wrap">     
</span>return 1</font></div><div><font size="1" face="monospace, 
monospace"><br></font></div><div><font size="1" face="monospace, 
monospace">}</font></div></div><div><br></div><div>Mas na verdade o tempo de 
execução piorou:</div><div><br></div><div>Original:</div><div><span 
style="font-family:monospace">real    0m2.069s </span><br 
style="font-family:monospace"><span style="font-family:monospace">user    
0m0.300s </span><br style="font-family:monospace"><span 
style="font-family:monospace">sys     0m1.644s</span><span 
style="font-family:monospace"><br></span></div><div><span 
style="font-family:monospace"><br></span></div><div><font face="arial, 
helvetica, sans-serif">Novo:<br></font><font face="monospace">real    0m2.857s
</font><br><font face="monospace">user    0m0.348s
</font><br><font face="monospace">sys     0m2.296s
</font><br><br><br>
<font face="arial, helvetica, sans-serif">Me parece contra-intuitivo, já que o 
original precisa checar em disco todas as vezes. Onde estou 
errado?</font></div><div><font face="arial, helvetica, 
sans-serif"><br></font></div><div><font face="arial, helvetica, 
sans-serif">Obrigado!</font></div><div><br></div></div></div></div></div>
</p>

    </div>
     

    
    <div style="color:#fff;height:0"></div>


</div>



  






</blockquote></div>

--000000000000f90a550578fade1c--

From address@hidden Wed Oct 24 08:53:46 2018
Return-Path: <address@hidden>
X-Sender: address@hidden
X-Apparently-To: address@hidden
X-Received: (qmail 13206 invoked by uid 102); 24 Oct 2018 15:53:46 -0000
X-Received: from unknown (HELO mtaq1.grp.bf1.yahoo.com) (10.201.224.239)
  by m5.grp.bf1.yahoo.com with SMTP; 24 Oct 2018 15:53:46 -0000
X-Received: (qmail 17845 invoked from network); 24 Oct 2018 15:53:46 -0000
X-Received: from unknown (HELO mta4001.groups.mail.bf1.yahoo.com) 
(10.201.194.219)
  by mtaq1.grp.bf1.yahoo.com with SMTP; 24 Oct 2018 15:53:46 -0000
X-Original-Return-Path: <address@hidden>
X-Received-SPF: pass (domain of gmail.com designates 209.85.166.44 as permitted 
sender)
X-YMailISG: xX8Z_pQWLDuIg0uqqwhWXrO7YoNSa2BYEwu56s7VjRMH_10o
 A.dbavtfC.jREXoGUjUeCi9YhW9EVXNYrFvCxNoazfj29U2cgFf1ON5oLVkX
 TCxRKt.cWxl9KRgyx01GD..GnubBShgTs2xOKt2XQJDffwXWPooT4heZ3Cu6
 frIWZb4fm55Rv4dOfl7HcUo.CQNwbVlC9HETnziFFan__2BLQecxGAtTbH4Q
 Zi61l3DvUuBJZ9yYxyei6N9IfHoar9Ncl0GNPMc.tu2DwC6upEY7kgLnyIiQ
 4HXqEAMKxTW.zthFzAivFl0VcUZT3_GBxUsPwKgJWatt98qLgNxY9sQ6dmkG
 yoW7DLLgWljpY7_SE984l1vKktoWwpOMxpnU4QJ3j7RMy68h0Cj7B97UaKfE
 H1cgfrwU9X4zGbUwElVrrTgA_9TTPnONLvru5Ta53BtooQSgZzau2zSYeok1
 ZWbavBi5xsjTVxuxnNcNgwmGmMahACE05Dk2KV0YLbcSJ9PMWVb8vO8ge_4j
 D3lqByArW9Swm4hy2R6KNUtMWabXNxnBuTeirbu5aTX7_AKHUm2k_X3mAPnl
 tZYpto7AhvlaaE7sKg_kO78WPuWAFqOCjLjG62wpY65bOJgPHIjq0DWj0llV
 sSalSAULTSwWgRlZNFwj2bXPvC_POiFtugJJwyMLg9h58SjU0nIrLL_gf4FB
 nkQytD1zy5R8hUUdO3Nlrk3ZiobTveMO15EGDj2.X0p_IjFl3mwE6.cU3b59
 lWz_5nK9GrhGcBm65VWnN6YkUliWqezp5EWw7qKlxQ8EnsQN5DEPFpogiasU
 kwRTrGLwOz5RPEGQtMCI5kgJkMWLzy.RT2ZwYN7iiL.v_7ULb3LZLUo97KvS
 .IDENYiVy8XoUhkoDWyktvPJEQC11z1E9hoS6DQqD2u640Sr2WJOfUiidMHb
 AarrCFwExSikzopUN88ot2mD9jPDRZcCRZ2B0NIK2ylTE7m.idLXTdQeeHQ2
 fHihlRxRJWbVTjgyHC5VNQgRY95HWbif_W9SClBv_nnLa.EvFbqYis8APCyK
 wACVBbTNRHqYIlKMPiUk9SAK.Zyaz5OeSonUco7apWJeQrVgStLk5nzu3Y7N
 4h81BegAPew6XPMQCpghWMLcE.ruHFlZ7QEm0d0cM.UyLmm0uu4zezucSfda
 tE5eaBUm0O7FbWicNhSrR5n0MOMf.rS0QMdlSD12Pcfas.G3uFHVVHMCEfvE
 cQ7nubcY7oIxkxhj8jpaOC0gG91gS8z1KWLDIUYTsa2zP.Erk07L_tfur.Rt
 KU5BpFtOnnkp3e6yaZuGXYJlqct_4DQMDapgdOtcYy4EFQyCaLa6Pr_AkXKe
 bMKaaA1d5O6AFoBJBIDS60MLn9WJNudsRJICsbmKp1Wlh4x_F4beKs7F4BFD
 BXUCi_NYDaYLxnIpsnyppet34W3vdjSPtEJzeoGPQvEGfdEVvIeXhc9.Gr_r
 ZCfsyjVJLZ6EuKrItYpoUQ80IOaA3102hN9kXDxqjCfE7iFb_Rw-
Authentication-Results: mta4001.groups.mail.bf1.yahoo.com  from=gmail.com; 
domainkeys=neutral (no sig);  from=gmail.com; dkim=pass (ok)
X-Received: from 127.0.0.1  (EHLO mail-io1-f44.google.com) (209.85.166.44)
  by mta4001.groups.mail.bf1.yahoo.com with SMTPS; Wed, 24 Oct 2018 15:53:45 
+0000
X-Received: by mail-io1-f44.google.com with SMTP id k17-v6so3459881ioc.4
        for <address@hidden>; Wed, 24 Oct 2018 08:53:45 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d100.net; s 161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to;
        bh=GATpGboUeVugjcL+C4bG55Mx4kb/E2TKr/2GjZMoMNM=;
        b=RU5sknnQN7ED7BNrIepcUUbmZ11P4xIMreYRIAYjwu6ht6DGPCaRGIC4nXVul3fol1
         qnuzZpOk2EmzvaD7nWwupepCXkbKgjX96MzacralL6qSHlKqsf+X3/ZbTn940JxWamJh
         +ANxyE5ej2BosWpgYagijlXi+K9HQB+cQyUbl4+h+OshvKjwg0MMNZrgfOo5yXC7G55i
         xxImbrl9rt0LiMktYt4JC1qtx5FSdVW5/PF6ECHIGQ+e3N9e26VPGybaMMt1G3yYyQ5l
         l1LiKgMtIRZvyZdigcf2+lH2zymwftj6PKMl3/NhYQfltHs5TDmB2+uEZOZcECZYgFvD
         5kDA=X-Gm-Message-State: 
AGRZ1gKPoqqlOKrahp/DjHmz511PC4PoYt9SQCN3GiWouX7DxM/+c/7C
        L3+E3fshDwkpl/9WtjUqBWux+g7vJODTsq9QK7Pni66F
X-Google-Smtp-Source: 
AJdET5fo2uGKLjVUswKluidEr5L5TBFp2FY3V9iDsTKHFSMU3i0/OUyaJB8E9Lp2ssFXSi+/6NHCh0OM1q4dL3hHrkoX-Received:
 by 2002:a6b:4908:: with SMTP id u8-v6mr13347593iob.181.1540396424717;
 Wed, 24 Oct 2018 08:53:44 -0700 (PDT)
MIME-Version: 1.0
References: <CACixCcb9o7pq0cNEREg=b=address@hidden>
 <CAJ=pi6k5LV8u-jT+P=address@hidden>
In-Reply-To: <CAJ=pi6k5LV8u-jT+P=address@hidden>
Date: Wed, 24 Oct 2018 12:53:33 -0300
Message-ID: <address@hidden>
To: address@hidden
Content-Type: multipart/alternative; boundary="000000000000b56cbd0578fb7d72"
X-Originating-IP: 10.201.194.219
Subject: Re: [shell-script] Array mais lento do que "-f $aquivo"
X-Yahoo-Group-Post: member; u27267252; 
y=uzw_nqnnl6QhkBdutaMOfYhLZuh8nccwm1TYlBxgPHwQAX3N
X-Yahoo-Profile: eribastos
From: Eri Ramos Bastos <address@hidden>

--000000000000b56cbd0578fb7d72
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Obrigado Júlio.

Melhorou, mas ainda inferior à original. Acho que vou manter o que tinha
mesmo. ;)

Com sua sugestão:
real    0m2.193s
user    0m0.328s
sys     0m1.772s

Original:
real    0m2.114s
user    0m0.268s
sys     0m1.768s

Abraços!

On Wed, Oct 24, 2018 at 12:17 PM 'Julio C. Neves' address@hidden
[shell-script] <address@hidden> wrote:

>
>
> Fala Eri
> Acho vc ganharia performance se fizesse:
>
> check_role() {
> local ROLES=($(ls /etc/roles)) || return 1
> for r in "${ROLES[@]}"; do
> [[ "$r" == "$1" ]] && return 0
> done
> }
>
> Abraços,
> Julio
>
> *» Não tem tempo para fazer um curso presencial?*
> *» Na sua cidade não tem nenhum bom curso de Linux?*
> *» **Conheça nosso portal educacional e estude conosco: *
> *     http://www.dicas-l.com.br/educacao
> <http://www.dicas-l.com.br/educacao/>*
> *»  Treinamento presencial (em 4 sábados) no RJ e BSB *
> *    em http://bit.ly/cursoshelljulioneves
> <http://bit.ly/cursoshelljulioneves>                   *
>
>
>
> *Também damos treinamento em sua empresa*
> *em qualquer cidade**, **com certificado **e nota fiscal.*
>
>
>
> Em qua, 24 de out de 2018 às 11:41, Eri Ramos Bastos address@hidden
> [shell-script] <address@hidden> escreveu:
>
>>
>>
>> Olá, lista!
>>
>> Tenho um script que roda a seguinte função ~300 vezes (sourced de outro
>> arquivo):
>>
>> check_role() {
>> if [ -d /etc/roles/ ]; then
>> if [ -f /etc/roles/$1 ]; then
>> return 0
>> fi
>> fi
>> return 1
>> }
>>
>> Pensei que iria ganhar performance fazendo isso:
>>
>> list_roles() {
>> if [ -d /etc/roles/ ]; then
>> cd /etc/roles
>> ls
>> else
>> echo ""
>> fi
>>
>> }
>>
>> export ROLES=($(list_roles))
>> check_role() {
>> local role=$1
>> for r in "${ROLES[@]}"; do
>> [[ "$r" == "$role" ]] && return 0
>> done
>> return 1
>>
>> }
>>
>> Mas na verdade o tempo de execução piorou:
>>
>> Original:
>> real    0m2.069s
>> user    0m0.300s
>> sys     0m1.644s
>>
>> Novo:
>> real    0m2.857s
>> user    0m0.348s
>> sys     0m2.296s
>>
>>
>> Me parece contra-intuitivo, já que o original precisa checar em disco
>> todas as vezes. Onde estou errado?
>>
>> Obrigado!
>>
>>
>
> 
>

--000000000000b56cbd0578fb7d72
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir="ltr">Obrigado Júlio.<div><br></div><div>Melhorou, mas ainda inferior 
à original. Acho que vou manter o que tinha mesmo. 
;)</div><div><br></div><div>Com sua sugestão:</div><div><span 
style="font-family:monospace"><span style="color:rgb(0,0,0)">real    0m2.193s
</span><br>user    0m0.328s
<br>sys     0m1.772s<br>
<br></span></div><div><font face="arial, helvetica, 
sans-serif">Original:</font></div><div><span 
style="font-family:monospace"><span style="color:rgb(0,0,0)">real    0m2.114s
</span><br>user    0m0.268s
<br>sys     0m1.768s<br>
<br></span></div><div><font face="arial, helvetica, 
sans-serif">Abraços!</font></div><br><div class="gmail_quote"><div dir="ltr">On 
Wed, Oct 24, 2018 at 12:17 PM &#39;Julio C. Neves&#39; <a 
href="mailto:address@hidden";>address@hidden</a> [shell-script] &lt;<a 
href="mailto:address@hidden";>address@hidden</a>&gt; wrote:<br></div><blockquote 
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc 
solid;padding-left:1ex">






        




<div>





<br><br>




<div dir="ltr"><div dir="ltr"><div style="font-family:monospace,monospace">Fala 
Eri</div><div style="font-family:monospace,monospace">Acho vc ganharia 
performance se fizesse:</div><div 
style="font-family:monospace,monospace"><br></div><div><div><font 
face="monospace, monospace">check_role() {</font></div><div><font 
face="monospace, monospace"><span style="white-space:pre-wrap">    </span>local 
ROLES=($(ls /etc/roles)) || return 1</font></div><div><font face="monospace, 
monospace"><span style="white-space:pre-wrap">        </span>for r in 
&quot;${ROLES[@]}&quot;; do</font></div><div><font face="monospace, 
monospace"><span style="white-space:pre-wrap">              </span>[[ 
&quot;$r&quot; == &quot;$1&quot; ]] &amp;&amp; return 0</font></div><div><font 
face="monospace, monospace"><span style="white-space:pre-wrap">        
</span>done</font></div><div><font face="monospace, 
monospace">}</font></div><div><font face="monospace, 
monospace"><br></font></div></div><div><div dir="ltr" 
class="m_7350348821723749737gmail_signature"><div dir="ltr"><div><div 
dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div 
dir="ltr"><div><div><div style="font-size:small">Abraços,</div></div><div 
style="font-size:small">Julio</div><div style="font-size:small"><br></div><div 
style="font-size:small"><font face="monospace, monospace"><b>» Não tem tempo 
para fazer um curso presencial?</b></font></div><div 
style="font-size:small"><font face="monospace, monospace"><b>» Na sua cidade 
não tem nenhum bom curso de Linux?</b></font></div><div><font face="monospace, 
monospace" style="font-size:small"><b>» </b></font><b><font face="trebuchet ms, 
sans-serif" style="font-size:12.8px">Conheça nosso portal educacional e estude 
conosco: </font></b></div><div><b><font face="trebuchet ms, sans-serif" 
style="font-size:12.8px">     h</font><span 
style="font-size:12.8px;font-family:&quot;trebuchet 
ms&quot;,sans-serif">ttp://<a href="http://www.dicas-l.com.br/educacao/"; 
style="color:rgb(17,85,204)" 
target="_blank">www.dicas-l.com.br/educacao</a></span></b></div><div><b>»  
Treinamento presencial (<font color="#660000" 
style="background-color:rgb(255,229,153)">em 4 sábados</font>) no RJ e BSB 
</b></div><div><b>    em <a href="http://bit.ly/cursoshelljulioneves"; 
style="color:rgb(17,85,204);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px"
 target="_blank">http://bit.ly/cursoshelljulioneves</a>                   
</b><img src="http://www.sindepolpb.com.br/novo3.gif"; 
style="font-size:12.8px"></div><div 
style="font-size:small"><br></div></div><div style="font-size:small"><img 
src="https://docs.google.com/uc?export=download&amp;id=1ht9llgh0CjQlapOqFtxVcSRCcopbeHYc&amp;revid=0B6Rg1uyhMVcbaVpnR2xqaXhpQ094RnNMYkZUeWhQZVZvdzFzPQ";
 width="420" height="48"><br></div><div><div style="font-size:12.8px"><span 
style="font-size:small;font-family:monospace,monospace"><font 
color="#000000"><b><br></b></font></span></div><div 
style="font-size:12.8px"><span 
style="font-size:small;font-family:monospace,monospace"><font 
color="#000000"><b>Também damos treinamento em sua 
empresa</b></font></span></div><div style="font-size:12.8px"><b 
style="font-size:12.8px"><font color="#660000" 
style="background-color:rgb(255,229,153)">em qualquer cidade</font></b><b 
style="font-size:12.8px;color:rgb(0,0,0)"><span 
style="font-family:monospace,monospace"><span style="font-size:small">, 
</span></span></b><b style="font-size:12.8px;color:rgb(0,0,0)"><span 
style="font-family:monospace,monospace"><span style="font-size:small">com 
certificado </span></span></b><b 
style="font-size:12.8px;color:rgb(0,0,0)"><span 
style="font-family:monospace,monospace"><span style="font-size:small">e nota 
fiscal.</span></span></b></div></div><div style="font-size:12.8px"><b 
style="color:rgb(0,0,0);font-size:12.8px"><span 
style="font-family:monospace,monospace"><span 
style="font-size:small"><br></span></span></b></div><div><div 
style="font-size:12.8px"><div style="font-size:small"><div 
style="font-family:monospace,monospace;display:inline"><font face="Bitstream 
Vera Sans, sans-serif"><font 
style="font-size:11pt"></font></font></div></div></div></div><div><blockquote 
style="font-family:arial;font-size:small;margin:0px 0px 0px 
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div 
bgcolor="#FFFFFF"><blockquote><div 
dir="ltr"></div></blockquote></div></blockquote></div>


<p style="margin-bottom:0cm"></p><div>
<p></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div
 class="gmail_quote"><div dir="ltr">Em qua, 24 de out de 2018 às 11:41, Eri 
Ramos Bastos <a href="mailto:address@hidden"; target="_blank">address@hidden</a> 
[shell-script] &lt;<a href="mailto:address@hidden"; 
target="_blank">address@hidden</a>&gt; escreveu:<br></div><blockquote 
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc 
solid;padding-left:1ex">


<u></u>









 
<div style="background-color:#fff">
<span style="display:none"> </span>


<div id="m_7350348821723749737m_-8880873497147591167ygrp-mlmsg">
  <div id="m_7350348821723749737m_-8880873497147591167ygrp-msg">


    <div id="m_7350348821723749737m_-8880873497147591167ygrp-text">
      
      
      <p></p><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Olá, 
lista!<div><br></div><div>Tenho um script que roda a seguinte função ~300 vezes 
(sourced de outro arquivo):</div><div><br></div><div><div><font 
face="monospace, monospace" size="1">check_role() {</font></div><div><font 
face="monospace, monospace" size="1"><span style="white-space:pre-wrap">       
</span>if [ -d /etc/roles/ ]; then<br></font></div><div><font face="monospace, 
monospace" size="1"><span style="white-space:pre-wrap">          </span>if [ -f 
/etc/roles/$1 ]; then</font></div><div><font face="monospace, monospace" 
size="1"><span style="white-space:pre-wrap">                    </span>return 
0</font></div><div><font face="monospace, monospace" size="1"><span 
style="white-space:pre-wrap">         </span>fi</font></div><div><font 
face="monospace, monospace" size="1"><span style="white-space:pre-wrap">       
</span>fi</font></div><div><font face="monospace, monospace" size="1"><span 
style="white-space:pre-wrap">       </span>return 1</font></div><div><font 
face="monospace, monospace" 
size="1">}</font></div></div><div><br></div><div>Pensei que iria ganhar 
performance fazendo isso:</div><div><br></div><div><div><font size="1" 
face="monospace, monospace">list_roles() {</font></div><div><font size="1" 
face="monospace, monospace"><span style="white-space:pre-wrap">    </span>if [ 
-d /etc/roles/ ]; then</font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre-wrap">              </span>cd 
/etc/roles</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">            </span>ls</font></div><div><font 
size="1" face="monospace, monospace"><span style="white-space:pre-wrap">       
</span>else</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">             </span>echo 
&quot;&quot;</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">        </span>fi</font></div><div><font size="1" 
face="monospace, monospace"><br></font></div><div><font size="1" 
face="monospace, monospace">}</font></div><div><font size="1" face="monospace, 
monospace"><br></font></div><div><font size="1" face="monospace, 
monospace">export ROLES=($(list_roles))</font></div></div><div><div><font 
size="1" face="monospace, monospace">check_role() {</font></div><div><font 
size="1" face="monospace, monospace"><span style="white-space:pre-wrap">        
</span>local role=$1<br></font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre-wrap">        </span>for r in 
&quot;${ROLES[@]}&quot;; do</font></div><div><font size="1" face="monospace, 
monospace"><span style="white-space:pre-wrap">             </span>[[ 
&quot;$r&quot; == &quot;$role&quot; ]] &amp;&amp; return 
0</font></div><div><font size="1" face="monospace, monospace"><span 
style="white-space:pre-wrap">    </span>done</font></div><div><font size="1" 
face="monospace, monospace"><span style="white-space:pre-wrap">     
</span>return 1</font></div><div><font size="1" face="monospace, 
monospace"><br></font></div><div><font size="1" face="monospace, 
monospace">}</font></div></div><div><br></div><div>Mas na verdade o tempo de 
execução piorou:</div><div><br></div><div>Original:</div><div><span 
style="font-family:monospace">real    0m2.069s </span><br 
style="font-family:monospace"><span style="font-family:monospace">user    
0m0.300s </span><br style="font-family:monospace"><span 
style="font-family:monospace">sys     0m1.644s</span><span 
style="font-family:monospace"><br></span></div><div><span 
style="font-family:monospace"><br></span></div><div><font face="arial, 
helvetica, sans-serif">Novo:<br></font><font face="monospace">real    0m2.857s
</font><br><font face="monospace">user    0m0.348s
</font><br><font face="monospace">sys     0m2.296s
</font><br><br><br>
<font face="arial, helvetica, sans-serif">Me parece contra-intuitivo, já que o 
original precisa checar em disco todas as vezes. Onde estou 
errado?</font></div><div><font face="arial, helvetica, 
sans-serif"><br></font></div><div><font face="arial, helvetica, 
sans-serif">Obrigado!</font></div><div><br></div></div></div></div></div>
<p></p>

    </div>
     

    
    <div style="color:#fff;height:0"></div>


</div>



  






</div></div></blockquote></div>






<br>


<br>




<div width="1" style="color:white;clear:both"></div>



</blockquote></div></div>

--000000000000b56cbd0578fb7d72--

reply via email to

[Prev in Thread] Current Thread [Next in Thread]