Need help on " if condition" in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on " if condition" in shell
# 8  
Old 02-29-2012
I have a query regarding the same.....

Are the below two scripts/Examples do the same functionality

Code:
Examples 1
.....
.....
printf "SK_BTS04A_hiQ_01b\n" | grep "[a-zA-Z].*[a-zA-Z0-9_-]" >/dev/null 2>&1
if [[ $? -ne 0 ]]
then
    echo 1
.....
.....

Code:
Examples 2
.....
.....
elif [[ SK_BTS04A_hiQ_01b != [a-zA-Z]*([a-zA-Z0-9_-]) ]]
then
    echo 1
.....
.....


Last edited by methyl; 02-29-2012 at 06:47 AM.. Reason: please user code tags
# 9  
Old 02-29-2012
No, the regex equivalent of the second example would be:
Code:
grep '^[a-zA-Z][a-zA-Z0-9_-]*$'

This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 02-29-2012
Data

Quote:
Originally Posted by Scrutinizer
No, the regex equivalent of the second example would be:
Code:
grep '^[a-zA-Z][a-zA-Z0-9_-]*$'


what would be equvalent to the first example....
# 11  
Old 02-29-2012
Code:
elif [[ SK_BTS04A_hiQ_01b != [a-zA-Z]*[a-zA-Z0-9_-] ]]

So that would mean that you are only interested in checking the first and the last character.
# 12  
Old 02-29-2012
Question

Quote:
Originally Posted by Scrutinizer
Code:
elif [[ SK_BTS04A_hiQ_01b != [a-zA-Z]*[a-zA-Z0-9_-] ]]

So that would mean that you are only interested in checking the first and the last character.

Hi,
should satisfy
"Name must start with letter [a-z][A-Z]." \
"The rest of the name must consist of a combination of" \
"letters, numbers, dashes, and/or underscores."

I am trying to achieve the same for both the examples. How can I go about it ?

Thanks
# 13  
Old 02-29-2012
Hi, see post #9 and your second example.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

5. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

8. Shell Programming and Scripting

shell "if" condition not executed

Hi, The below script should should create a file "COUNTFILE.log" if not found. But I am trying to run this and it is not creating the file . #!/bin/sh find . -name "COUNTFILE.log" > /dev/null 2>&1 if ; then echo 0> COUNTFILE.log fi Please advice why it is not creating... (8 Replies)
Discussion started by: himvat
8 Replies

9. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question