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

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

Re: [shell-script] Problema tentando criar array


From: Flavio Junior
Subject: Re: [shell-script] Problema tentando criar array
Date: Mon, 15 Dec 2008 17:32:12 -0200

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

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

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

[root@bloo ~]# bash x.sh
Services: telnet ftp imap dns pop3 smtp Total: 6
[root@bloo ~]# chmod +x x.sh
[root@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 <address@hidden>

>   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 ${#teste[@]}
> 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]



reply via email to

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