Sample Header Ad - 728x90

linux tcsh scripting question

0 votes
0 answers
140 views
I am writing a linux tcsh script to check the syntax of a command argument to insure its correct before the command executes.
Out of the 9 fields I have saved as variables in the script, I am able to get 7 of them checked. I only have 2 remaining and they are both confounding me with the same issues.
The first one is a check of "tco14" or "tc14a" these are 2 examples of the same field I need to have the script check.
The preceding 2 examples will always break down like this:
"tc" will always begin this argument followed by the next 2 positions which should be numbers between 1-9 then the final position which can be either a number or a letter. In bash I had it working with these lines: # Check the seventh field check_field "$var7" 'TC([0-9]{3}|[0-9]{2}[a-zA-Z])$' "Field 7 is not valid:" 7 That script used arrays in getting the cheeck accomplished, HOWEVER as I found out in tcsh it doesnt play nice with ALOT of bash scripting. So Ive tried the following in tcsh: # Check if field7 matches the specified format set valid_field7 = expr "$field7" : '^tc[0-9]\{1,3\}[a-zA-Z0-9]$' if ($valid_field7 == 0) then echo "${RED}Error: Invalid syntax for field7. Must start with 'tc' followed by 2 digits and end with a digit or a letter.${NC}" exit 1 endif This almost works but it also passes the check with tc12 which it shouldnt. Again this field of the argument needs 3 character the first 2 are numbers and the last one is a number or a letter. Reference following lines for possibly a better understanding: - First Position = t - Second Position = c - Third Position = number between 0-9 - Fourth Position = number between 0-9 - Fifth Position = a letter or a number between 0-9
Asked by Brian (5 rep)
Nov 22, 2023, 01:05 AM
Last activity: Nov 30, 2023, 08:29 PM