Sponsored Content
Top Forums Shell Programming and Scripting Case statement in UNIX shell script Post 302967354 by Mohan0509 on Tuesday 23rd of February 2016 06:35:39 AM
Old 02-23-2016
Case statement in UNIX shell script

have written the below code to check whether the string received from user is a file name or dir using case statement, but its going into default case*).

Code:
#!/bin/sh
#Get a string from user and check whether its a existing filename or not
rm str2
rm str3
echo "enter a file \c"
read fil
#echo $fil
grep $fil fl >> str2 #fl has all filename stored in it using ls -l >> fl
cut -c 1-1 str2 >> str3
cat str2
cat str3 #it has the value '-'
case "$str3" in
-) echo "you have entered a filename" ;;
*) echo "not a filename"
exit ;;
esac

can someone help me please..

Last edited by vbe; 02-23-2016 at 07:41 AM.. Reason: code tags please
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script automation using case statement

Hi, I'm trying to write a shell script that has a menu and then dependant on the selection, will automate some samba file transfer. The problem is when I run the code without the case statement it runs fine. but when I put the case statement in the only way I can get the code to run is to... (6 Replies)
Discussion started by: ianf
6 Replies

2. Shell Programming and Scripting

what is problem with this small shell script.. case statement related

Hi All, this small script is written to recognize user input character.. it is in small case .. upeer case or is a number... but when i input first capital letter say A.. it always gives small character.... what is the problem. #!/bin/bash echo "Enter the character" read a case $a in )... (2 Replies)
Discussion started by: johnray31
2 Replies

3. Shell Programming and Scripting

shell script case statement

In a case statement like below : case $rental in "car") echo "For $rental Rs.20 per k/m";; "van") echo "For $rental Rs.10 per k/m";; "jeep") echo "For $rental Rs.5 per k/m";; "bicycle") echo "For $rental 20 paisa per k/m";; *) echo "Sorry, I can not gat a $rental for you";;... (4 Replies)
Discussion started by: sriram003
4 Replies

4. UNIX for Dummies Questions & Answers

case statement in UNIX scripting (ksh)

Hi, I have a script like below : #!/bin/ksh echo "Do you want to export all docs ?" read alld echo "Do you want to export template or report only " read temr case && ] #arguments ;; case && ] #arguments ;; case && ] #arguments ;; (4 Replies)
Discussion started by: luna_soleil
4 Replies

5. Shell Programming and Scripting

Shell case statement

echo -e "Select: \c" read IN pattern="1-20" case $IN in ) echo "Selected: $IN" ;; *) echo "Invalid selection: $IN" ;; esac # sh test Select: 10 Invalid selection: 10 # sh test Select: 2 (6 Replies)
Discussion started by: Ikon
6 Replies

6. Shell Programming and Scripting

Trouble in getting user input while using CASE statement in UNIX

i want to get user input like this please tell which option to chose 1. mango 2. tango 3. rango if user chooses mango then it should execute a set of statements and again ask like this what do you want to do 1.add 2.subtract 3.exit when i choose exit it should goto my previous menu... (4 Replies)
Discussion started by: s.deepak
4 Replies

7. Shell Programming and Scripting

Help on case to call recursively in UNIX Shell Script

Hi, I am New to Unix Shell Scripting basically, i need some help in achieving a case statement in Shell script to call recursively That is if case having like 1 2 3 4 options , if user inputs 1 and gets executed case should ask for options again but user should not input the same input value 1,... (7 Replies)
Discussion started by: karthikram
7 Replies

8. Shell Programming and Scripting

Using shell to generate case statement

Hi Gurus, I have a very weird requirement and have no clue to resolve the issue. please help me get out this difficulty below two tables, table1 contains the column name. D means this column used for the rule. for example: rule 0 is all columns have value, rule1 is col3 and col7 have no value.... (2 Replies)
Discussion started by: Torhong
2 Replies

9. Shell Programming and Scripting

Shell scripting with case statement

Foe example we have three environments int,qa and prod.Each environment has some number of servers. int=Server1,Server2,Server3 qa=Server4,Server5,Server6 prod=Server7,Server8,Server9 echo "Enter the Environment i.e int,qa,prod" read env case $env in int) ## Need command where all the... (9 Replies)
Discussion started by: nareshreddy443
9 Replies

10. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies
STRNATCASECMP(3)							 1							  STRNATCASECMP(3)

strnatcasecmp - Case insensitive string comparisons using a ";natural order" algorithm

SYNOPSIS
int strnatcasecmp (string $str1, string $str2) DESCRIPTION
This function implements a comparison algorithm that orders alphanumeric strings in the way a human being would. The behaviour of this function is similar to strnatcmp(3), except that the comparison is not case sensitive. For more information see: Martin Pool's Natural Order String Comparison page. PARAMETERS
o $str1 - The first string. o $str2 - The second string. RETURN VALUES
Similar to other string comparison functions, this one returns < 0 if $str1 is less than $str2 > 0 if $str1 is greater than $str2, and 0 if they are equal. SEE ALSO
preg_match(3), strcmp(3), strcasecmp(3), substr(3), stristr(3), strncasecmp(3), strncmp(3), strstr(3), setlocale(3). PHP Documentation Group STRNATCASECMP(3)
All times are GMT -4. The time now is 08:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy