установите параметры командной строки

как я могу установить "переменную" как параметр командной строки для некоторой cli программы.

я раньше делал это в песнях этот путь:

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

как я могу сделать это на человечности?

это - сценарий оболочки, который я использую:

#!/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

я получаю синтаксическую ошибку:

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
1
задан 30 November 2015 в 11:09

2 ответа

Ваше использование сценария csh синтаксис, таким образом, это не допустимое sh сценарий. Минимальная фиксация для этого должна использовать sudo csh вместо sudo sh.

Однако csh не очень популярно, на серьезных основаниях; возможно, надлежащая фиксация должна была бы переписать Ваш сценарий в bash (или даже портативный POSIX sh) синтаксис.

Кроме set кажется, нет ничего в Вашем сценарии, который конкретно использует csh функции. sh синтаксис для установки переменной

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

Отсутствие set ключевое слово и отсутствие пробелов вокруг равняются знаку, и значительные и важные изменения.

Существует также много ошибок опции, которые являются (я размышляю), из-за использования различных версий программ. Я незнаком с этими инструментами, так не может рекомендовать, обновить ли, понизить или заменяет их. Переключение на csh вместо sh не изменится, какие опции Вам разрешают использовать с этими программами. Возможно, Вы захотите отправить отдельный вопрос с большим количеством фона - который версии grdcut, grdgradient, grdimage, pscoast, pstext и т.д. эти сценарии были записаны для, какие версии Вы установили теперь, и/или возможно, что Ваш сценарий на самом деле пытается выполнить.

0
ответ дан 30 September 2019 в 02:27

Я предполагаю, что Вы не работаете csh, но bash. Можно узнать, какую оболочку Вы выполняете путем ввода в echo $SHELL.

можно переключиться на Оболочку C, чтобы иметь все как прежде, или можно адаптировать сценарии к Bash.

Вот то, как изменить Ваш Shell

Для определения переменных в Bash, Вам не нужно set ключевое слово:

my_message="hello"
echo "$my_message"
0
ответ дан 30 September 2019 в 02:27

Другие вопросы по тегам:

Похожие вопросы: