shell - Need to give option Y or N in DCL scripting -
my requirement -- need give 2 options(yes or no) users. whenever user enters other y or n system should throw error. created below piece of code, not giving expected output.
$ y:== y $ n:== n $ alpha: $ inquire option "y or n" $ define/nolog report_file 'option' $ if f$type (option) .eqs. "integer" $ $ esc[0,7] = 27 $ text = "numeric values not accepted !!" $ write sys$output "''esc'[5m''text'''esc'[m" $ wait 0:0:0.15 $ set term/width=132 $ goto alpha $ endif $ if 'option' .nes. y $ $ esc[0,7] = 27 $ text = "enter "y" or "n"" $ write sys$output "''esc'[5m''text'''esc'[m" $ endif $ if 'option' .nes. n $ $ esc[0,7] = 27 $ text = "enter "y" or "n"" $ write sys$output "''esc'[5m''text'''esc'[m" $ endif
- output :
whenever try give interger values running designed.. when trying enter a,b,c etc other y or n, giving below warning.
aksh - $-> @test.com y or n: k %dcl-w-undsym, undefined symbol - check validity , spelling \k\ %dcl-w-undsym, undefined symbol - check validity , spelling \k\ %dcl-w-undsym, undefined symbol - check validity , spelling \k\
any suggestions on ??
hmmm, seems me need un-quote string compare variable , and quote fixed string values:
bad: if 'option' .nes. y good: if option .nes. "y"
some folks goof: if "''option'" .nes. "y" ! show value option when run set verify
free advice...
1) never assign values before verifying: - define/nolog report_file 'option' ---> move bottom of script after validation ---> use "''option'" if ever want accept spaces in option answer (not case)
2) little nicer users - consider using f$extract first character of option allows "yes" (and "yeah!") - use f$edit uppercase before comparing. - consider using f$loc find option in list of acceptable values "yynn"
try this:
$ y:== y $ n:== n $ esc[0,7] = 27 $alpha: $ inquire option "y or n" $ if option .nes. y .and. option .nes. n $ $ text = "enter ""y"" or ""n""" $ write sys$output esc + "[5m" + text + esc + "[m" $ goto alpha $ endif $ define/nolog report_file 'option'
Comments
Post a Comment