set parâmetros da linha de comandos

1

como posso definir uma "variável" como parâmetro de linha de comando para algum programa cli.

Eu costumava fazer isso no centos dessa maneira:

    set var = "-x"
someprogram $var --other-parameters

como posso fazer isso no Ubuntu?

este é o script de shell que estou usando:

#!/bin/csh

#####
#    Define Mercalli projection: Center_lon/Center_Lat/Plot_Width   
#####
set PROJ = "-Jm1.4"

#####
#    Define map bounds: MINLON/MAXLON/MINLAT/MAXLAT 
#####
#set REG = "-R38.0/47.0/34.0/37.0"
set REG = "-R40.0/49.0/28.0/38.0"
/bin/rm gmt.ps

######
#   cut region from "middlEST.grd" and name "map.grd"
######
#grdcut middlEST.grd -Gmap.grd $REG
grdcut topo1.grd -Gmap.grd $REG
grdcut topo1.grd -R-38/-49/28/38 -Gnecar.grd
grdcut topo1.norm -R-38/-49/28/38 -Gnecar.grd


######
#   Compute the gradient of topography
######
grdgradient map.grd -Gmap1.grd -A0 -Nt1.0 -V -M
#grdgradient map.grd -Gmap1.grd -A0 -Ne0.5 -V -M

######
#   USING grdhsuteq
######
grdhisteq map1.grd -Gmap2.grd -N

######
#   USING grdmath
######
grdmath map2.grd 0.1 MUL = map2.grd

######
#   plot topography in 2-D color using "relief1.cpt, relief2.cpt, topo.cpt, or globe.cpt"; 
#   write to postscript file; remove map.grd
######
grdimage map.grd -Ctopo.cpt $REG $PROJ -Imap2.grd -V -K > gmt.ps
#grdimage map.grd -Crelief1.cpt $REG $PROJ -Imap2.grd -V -K > gmt.ps 
#grdimage map.grd -Crelief2.cpt $REG $PROJ -Imap2.grd -V -K > gmt.ps
#grdimage map.grd -Cglobe.cpt $REG $PROJ -Imap2.grd -V -K > gmt.ps
/bin/rm map.grd

######
# to plot coastlines, pscoast options:
#   -Rw/e/s/n : the map boundarys
#   -K : allow more operations to add into current map "map.ps"
#   -O : overlay current operation to map "map.ps"
# projections:  
#   -Jx ==> black-white frame
#   -Jb ==> no black_white frame only major tick marks
#   -Jm : mecator projection
#   (1.40: the number following the projection option means 1.4 inch
#        for 1 degree)
#
#   -S : symbol
#       -Sc circle
#       -Sa star
#       -Sd diamond
#       -Si inverted triangle
#       -St triangle
#       -Ss square
#
#   -G200 : fill the inner area of symbol with 200 in gray scale 
#       (0-255) (black-white)
#   -Gr/g/b : fill with color; 3 elementary color REG GREEN BLUE in scale
#       (0-255) (dark-bright) 
#
#   -P : portrait
#
#   -D : resolution (f=full, h=high, i=intermediate)
#
#   -B : border
#        10: write number every 10 degree
#        f5: plot ticks every 5 degree
#
#   -L : plots the map scale
#
#   -W3 : the coast line width is 3 (pts.)
#
#   -I : plot river
#
#   -S : fill the "wet" land with color (e.g. lake)
#
#   -N : plot plotical boundary 1=national 2=state
######

######
#   plot coastline:
######
pscoast $REG $PROJ -P -Df -B1f1 -Na/5/0/0/0 \
-L40.00/28.80/33.40/300 \
-S150/225/255 -V -O -K >> gmt.ps

######
#PLOT FAULTS BY USING FAULTS.car file
######
#psxy FAULTS.car -P $REG $PROJ -O -Sc0.04 -W0/0/255 -G0/0/255 -V -K >> gmt.ps 

######
#   PLOT Numan's Tectonic Divisions
######
#psxy Numan.txt -P $REG $PROJ -O -Sc0.03 -W255/0/0 -G255/0/0 -V -K >> gmt.ps 

#####
#    PLOT BEACH-BALLS
#####
#   Plot Beach-Ball of Focal Mechanism Solutions (FMS) accordinc to -Scscale
#   FMS.txt has solutions of many events. Each solution include:
#   Long Lat Depth Strike-1 Dip-1 Rake-1 Strike-2 Dip-2 Rake-2 Mantissa Exponent NewLong NewLat Title
#   If you have Mo=2.2e+21 dyne-cm, that means Mantissa=2.2 and Exponent=21
#   Note that, you need to modify NewLong and NewLat if you want to place a Beach-Ball in a specific place in the figure.
#   If you want to place a Beach-Ball in the same location type 0 0 or -c insteade of NewLong NewLat.
#   The -: option will intercahnge the order of Long Lat and NewLong NewLat.
#   Title is optional
######
#psmeca FMPAPER.txt -P $REG $PROJ -O -: -Sc1 -G0 -W1p -K -V >> gmt.ps
#psmeca FMPAPER.txt -P $REG $PROJ -O -: -Sc1 -G0 -W1p -CP0.2 -K -V >> gmt.ps
#psvelomeca FMS.txt -P $REG $PROJ -O -: -Sc1 -G0 -W1p -K -V >> gmt.ps
#psvelomeca needs lon lat strike dip rake Mw 

######
#   PLOT STRESS CROSSES 
######
#psvelo STRESS-P.txt $REG $PROJ -Sx0.2 -W3/255/0/0 -V -O -K -: EOF >> gmt.ps

######
#   PLOT EARTHQUAKES
######
#psxy SEISMISITY.txt -P $REG $PROJ -O -: -Sc0.15 -W0 -G255/0/0 -V -K >> gmt.ps 

######
#   plot text: state, city names
######
#       pen positions for text:
#                                (center)
#                                   |
#       (lower right-justified) 11  10  9 (lower left-justified)
#       (middle  "      "    )  7   6   5 (middle   "      "    )
#       (upper   "      "    )  3   2   1 (upper    "      "   )
#
#   column:
#   1=lat 2=lon 3=point size 4=text angle 5=font 6=pen position 7=text
######
pstext $REG $PROJ -V -O -: <<EOF>> gmt.ps
37.50 41.00 18   0.0   1  6 TURKEY
35.00 39.50 20   35.0  1  6 SYRIA
33.00 42.98 22   0.0   1  6 I  R  A  Q
34.00 47.50 22  -40.0  1  6 IRAN
30.00 41.00 16  -30.0  1  6 S A U D I   A R A B I A
29.50 48.00 13.5 0.0   1  6 KUWAIT
32.50 38.50 13   60    11 6 JORDAaN
#36.90 44.60 12 0.0 1 6 1
#36.75 44.30 12 0.0 1 6 2A
#36.40 44.20 12 0.0 1 6 2B
#35.70 43.80 12 0.0 1 6 2C
#33.80 44.00 12 0.0 1 6 3
#34.40 42.60 12 0.0 1 6 3
#34.90 41.80 12 0.0 1 6 3
EOF

exit 0

######
#   plot color topo scale
######

#psscale -D17/4/8/1 -Ccpt.relief -B500 -O -S -K>>gmt.ps

eu recebo um erro de sintaxe:

sudo sh IRAQ1
grdcut: Syntax error: Must specify only one of the -R, -S or the -Z options
grdcut: Syntax error -R option.  Correct syntax:
    -R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
      Append r if giving lower left and upper right coordinates
    -Rg or -Rd for global domain
    -R<grdfile> to take the domain from a grid file
grdcut: Syntax error -R option.  Correct syntax:
    -R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
      Append r if giving lower left and upper right coordinates
    -Rg or -Rd for global domain
    -R<grdfile> to take the domain from a grid file
grdgradient: Error for input file: No such file (map.grd)
grdgradient: Warning: Option -M is deprecated; -fg was set instead, use this in the future.
grdgradient: Syntax error: Must specify input file
grdimage: Error for input file: No such file (map.grd)
grdimage: Syntax error: Must specify a map projection with the -J option
grdimage: Syntax error: Must specify one (or three) input file(s)
/bin/rm: cannot remove ‘map.grd’: No such file or directory
pscoast: Warning: 5/0/0/0 not a valid number and may not be decoded properly.
pscoast: Error: Your -Dg reference point coordinates require both -R -J to be specified
pscoast: Syntax error: Must specify -R option
pscoast: Syntax error: Must specify a map projection with the -J option
pstext: Syntax error: Must specify -R option
pstext: Syntax error: Must specify a map projection with the -J option
    
por Mohammed 30.11.2015 / 09:09

2 respostas

0

Seu script usa a sintaxe csh , por isso não é um script sh válido. A correção mínima para isso é usar sudo csh em vez de sudo sh .

No entanto, csh não é muito popular, por boas razões; talvez a correção adequada seja reescrever seu script na sintaxe bash (ou mesmo POSIX sh ).

Além do set , parece não haver nada em seu script que use especificamente os recursos csh . A sintaxe sh para definir uma variável é

PROJ="-Jm1.4"
REG="-R40.0/49.0/28.0/38.0"

A ausência da palavra-chave set e a ausência de espaços ao redor do sinal de igual são mudanças significativas e importantes.

Existem também muitos erros de opção que são (eu especulo) devido ao uso de versões diferentes dos programas. Não estou familiarizado com essas ferramentas, por isso não posso recomendar se atualizo, faço downgrade ou as substituo. Mudar para csh em vez de sh não alterará quais opções você tem permissão para usar com esses programas. Talvez você queira postar uma pergunta separada com mais informações - quais versões de grdcut , grdgradient , grdimage , pscoast , pstext etc. esses scripts foram escritos para, quais versões você instalou agora e / ou talvez apenas o que seu script realmente tenta realizar.

    
por tripleee 30.11.2015 / 10:57
0

Suponho que você não esteja executando csh , mas bash . Você pode descobrir que tipo de shell você está executando digitando echo $SHELL .

Você pode mudar para o C-Shell para ter tudo como antes ou pode adaptar seus scripts para o Bash.

Veja como alterar seu Shell

Para definir variáveis no Bash, você não precisa da palavra-chave set :

my_message="hello"
echo "$my_message"
    
por Stefano Palazzo 30.11.2015 / 09:17