• Post Reply Bookmark Topic Watch Topic
  • New Topic

unix shell script  RSS feed

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I want to write a shell script program call "ccompute" and use that program to invoke other SAS program.
I need to take in 3 parameter

ccompute Version1 USA 20040630 20040731

if the format is not valid
echo

Format should be :

ccompute [Version] [Country] [start date] [end date]

and I will store this 4 parameters into variable.

Can anyone help me?
Thanks a lot!

Jack
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have much experience with shell scripting, but I happened to have this handy link to an on-line book on Linux and Bash.
 
Pat Flickner
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'm going to assume you may want something like a c-shell:

#!/usr/bin/csh

if ($#argv < 4) then
echo " "
echo "You must enter these four arguments:"
echo " "
echo " version"
echo " country"
echo " start date (MMDDYYYY)"
echo " end date (MMDDYYYY)"
echo " "
exit
else
$SASHOME -autoexec $HOME/autoexec.sas -sysparm "$1-$2-$3-$4" sasjob.sas \&
endif


Does that help?

Pat
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a #!/bin/csh -f
shell script which already taken in the parameters which user input
and a driver list with the country
country.txt
USA
HKG
KOR

set version = $1
set country = $2
set start = $3
set end = $4

example: versionA, USA, 20030723, 20040724

I want to have some error checking:
1) Check whether $3 $4 is a valid date
2) Check whether $2 is in the country.txt
3) output location:
echo start location: /place/200307
echo start location: /place/200407
I don't know how to use substr function here and keep giving me syntax error
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

generates a file with that timestamp.
Then extracts the generated date, and compares it to the parameter.
This is neccessary, because 'touch 20031232' corrects the date to '20040101'.


Exitcode 0 indicates success, else: failure.
You can test it with:
sh inlist.sh foo && echo "yes"
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks stefan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!