-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Engraçado..
Aqui funcionou normalmente..
Por acaso não ta setando #!/bin/sh ?

veja:
[r...@bloo ~]# cat x
64.233.169.99 google.com # telnet ftp imap dns pop3 smtp
[r...@bloo ~]# cat x.sh
#!/bin/bash -x
services=($(cat x | cut -d\# -f2))
echo "Services: ${servic...@]} Total: ${#servic...@]}"

[r...@bloo ~]# bash x.sh
Services: telnet ftp imap dns pop3 smtp Total: 6
[r...@bloo ~]# chmod +x x.sh
[r...@bloo ~]# ./x.sh
+ services=($(cat x | cut -d\# -f2))
++ cat x
++ cut -d# -f2
+ echo 'Services: telnet ftp imap dns pop3 smtp Total: 6'
Services: telnet ftp imap dns pop3 smtp Total: 6


Inicialmente eu testei sem o cat: cut -d\# -f2 arquivo.txt, funcionou
tambem...

- --

Flávio do Carmo Júnior aka waKKu


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: http://getfiregpg.org

iEYEARECAAYFAklGsLsACgkQgyuXjr6dyksALQCfUycnvKcuHaMNPzlStZyYYMtf
n08An3PM3kQmub4On3edHPIYPVTP4xJ/
=xM4+
-----END PGP SIGNATURE-----
2008/12/15 Eri Ramos Bastos <[email protected]>

>   Olá, lista.
>
> Estou apanhando um pouco para criar um array dentro de um script.
>
> Tenho um arquivo chamado batata.txt:
>
> $ cat batata.txt
> 64.233.169.99 google.com # telnet ftp imap dns pop3 smtp
>
> Via linha de comando consigo facilmente criar um array para os
> serviços relacionados:
>
> $ teste=($(cat batata.txt |cut -d "#" -f2))
> $ echo ${#tes...@]}
> 6
>
> Porém dentro de um script onde tenho uma função que recebe a linha via
> argumento isso não funciona:
>
> http://pastebin.com/m5e4b6f75
>
> $ ./view.sh
> 64.233.169.99
> + services=($(echo "$1"|cut -d "#" -f2))
> ++ echo '64.233.169.99 google.com # telnet ftp imap dns pop3 smtp '
> ++ cut -d '#' -f2
> + set +x
> Numero de elementos: 1
> Conteudo da variavel $services: telnet ftp imap dns pop3 smtp
>
> Certeza que estou vacilando em algum detalhe, mas não consigo encontrar
> onde.
> Alguém pode me dar uma luz? :)
>
> []'s
> Eri Ramos Bastos
>  
>


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

Responder a