Como modificar um shell csh para bash ? [RESOLVIDO]

1. Como modificar um shell csh para bash ? [RESOLVIDO]

Arthur Lucas
arthurlucas

(usa Ubuntu)

Enviado em 29/05/2014 - 20:58h

#!/bin/csh
#################################################################
# Csh Script to retrieve 2 online Data files of 'ds083.2',
# total 31.38M. This script uses 'wget' to download data.
#
# Highlight this script by Select All, Copy and Paste it into a file;
# make the file executable and run it on command line.
#
# You need pass in your password as a parameter to execute
# this script; or you can set an environment variable RDAPSWD
# if your Operating System supports it.
#
# Contact schuster@ucar.edu (Doug Schuster) for further assistance.
#################################################################

set pswd='lucas88262808'
if(x$pswd == x && `env | grep RDAPSWD` != '') then
set pswd = $RDAPSWD
endif
if(x$pswd == x) then
echo
echo Usage: $0 YourPassword
echo
exit 1
endif
set v = `wget -V |grep 'GNU Wget ' | cut -d ' ' -f 3`
set a = `echo $v | cut -d '.' -f 1`
set b = `echo $v | cut -d '.' -f 2`
if(100 * $a + $b > 109) then
set opt = 'wget --no-check-certificate'
else
set opt = 'wget'
endif
set opt1 = '-O /dev/null --save-cookies auth.rda_ucar_edu --post-data'
set opt2 = "email=arthur.lucas.melo@gmail.com&passwd=$pswd&action=login"
$opt $opt1="$opt2" https://rda.ucar.edu/cgi-bin/login
set opt1 = "-N --load-cookies auth.rda_ucar_edu"
set opt2 = "$opt $opt1 http://rda.ucar.edu/data/ds083.2/";
set filelist = ( \
grib2/2014/2014.01/fnl_20140101_00_00 \
grib2/2014/2014.01/fnl_20140101_06_00 \
)
while($#filelist > 0)
set syscmd = "$opt2$filelist[1]"
echo "$syscmd ..."
$syscmd
shift filelist
end

rm -f auth.rda_ucar_edu
exit 0





Gostaria de modificar o código acima para bash, quando eu coloco #!/bin/bash na primeira linha da erro, o que eu posso fazer ? Não entendo esse código!!


  


2. MELHOR RESPOSTA

Sandro Marcell
smarcell

(usa Slackware)

Enviado em 03/06/2014 - 18:18h

Cara a sintaxe do csh é totalmente diferente da do bash/sh! Scripts feitos em cshell só rodam no cshell. Portanto, ou você deixa o script como está, usando o csh ou então, reescreve totalmente ele para o sh/bash.


3. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Carlos A. P. Cunha
Carlos_Cunha

(usa Linux Mint)

Enviado em 30/05/2014 - 02:06h

o que vc não entende?Se saber usar o BASH e so ajustar para o que precisa da forque BASH entende!!


4. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Luis R. C. Silva
luisrcs

(usa Linux Mint)

Enviado em 30/05/2014 - 07:18h

E que erro dá?


5. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Vinicius Miqueloti
Miqueloti

(usa Lubuntu)

Enviado em 30/05/2014 - 13:08h

Primeiramente, há bash em seu sistema?

Se não tiver baixe o pacote correspondente a sua distro/sistema e instale.

Para testar digite um simples bash no terminal e vê.


6. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Alberto Federman Neto.
albfneto

(usa openSUSE)

Enviado em 30/05/2014 - 13:55h

descreva o erro que ocorre,para que possam verificar.
como falaram, veja tb se sua shell padrão é bash:

$ echo $SHELL

pq em muitos linux, é, mas não em todos.




7. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Arthur Lucas
arthurlucas

(usa Ubuntu)

Enviado em 03/06/2014 - 16:45h

rei_astro escreveu:

E que erro dá?


Quando eu coloco #!bin/bash

da o seguinte erro:

./baixar.csh
./baixar.csh: linha 38: erro de sintaxe próximo do `token' não esperado `('
./baixar.csh: linha 38: `set filelist = ( \'



8. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Arthur Lucas
arthurlucas

(usa Ubuntu)

Enviado em 03/06/2014 - 16:46h

Isso ai em cima é erro de sintaxe, mas quando eu troco o que ele pede, da outro erro!


9. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Luis R. C. Silva
luisrcs

(usa Linux Mint)

Enviado em 03/06/2014 - 17:16h

Ao meu ver, esses são os erros:

set opt2 = "$opt $opt1 http://rda.ucar.edu/data/ds083.2/\"; -> remover a barra invertida
set filelist = ( \
grib2/2014/2014.01/fnl_20140101_00_00 \
grib2/2014/2014.01/fnl_20140101_06_00 \ -> remover os parênteses e barras invertidas, colocar em uma única linha
)
while($#filelist > 0) -> remover parênteses.

Ficando:

set opt2 = "$opt $opt1 http://rda.ucar.edu/data/ds083.2/";
set filelist = "grib2/2014/2014.01/fnl_20140101_00_00" "grib2/2014/2014.01/fnl_20140101_06_00" -> tem 2 arquivos aqui.
while $#filelist > 0


10. Re: Como modificar um shell csh para bash ? [RESOLVIDO]

Alberto Federman Neto.
albfneto

(usa openSUSE)

Enviado em 03/06/2014 - 22:26h

@SMarcell,
benvindo novamente, a tempos não vejo vc aqui. Nosso Guru do Shell e da zsh! Como vai?


@Arturlucas,
é o seguinte, a maneira mais fácil de vc usar esse script... instale o pacote csh, depois abra um terminal e digite

# csh

seu terminal vai estar momentâneamente em csh e poderá executar o script... ele vai voltar para bash, assim que fechar o terminal a não seu que vc troque a shell.






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts