1

how can i set a "variable" as command line paramter for some cli program.

i used to do that in centos this way:

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

how can i do this on ubuntu?

this is the shell script i'm using:

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

i get a syntax error:

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
0

Your script uses csh syntax so it is not a valid sh script. The minimal fix for that is to use sudo csh instead of sudo sh.

However, csh is not very popular, for good reasons; perhaps the proper fix would be to rewrite your script in bash (or even portable POSIX sh) syntax.

Apart from the set there doesn't seem to be anything in your script which specifically uses csh features. The sh syntax to set a variable is

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

The absence of the set keyword and the absence of spaces around the equals sign are both significant and important changes.

There are also many option errors which are (I speculate) due to using different versions of the programs. I am unfamiliar with these tools, so cannot recommend whether to upgrade, downgrade, or replace them. Switching to csh instead of sh will not change which options you are allowed to use with these programs. Perhaps you'll want to post a separate question with more background -- which versions of grdcut, grdgradient, grdimage, pscoast, pstext etc these scripts were written for, which versions you have installed now, and/or perhaps just what your script actually attempts to accomplish.

  • Thanks, everything is clear now. I edited the script to match the bash syntax. Actually all these programs belong to a single package (GMT) and they work perfectly together – Mohammed Nov 30 '15 at 21:01
0

I assume you're not running csh but bash. You can find out what type of shell you're running by typing in echo $SHELL.

You can switch to the C-Shell to have everything like before, or you can adapt your scripts for Bash.

Here's how to change your Shell

To define variables in Bash, you don't need the set keyword:

my_message="hello"
echo "$my_message"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.