UNIX shell script question.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX shell script question.
# 1  
Old 11-12-2015
UNIX shell script question.

I need to check whether the directory is exist or not. only three letter will be passed as argument. from that it should pick the entire directory.


Instead of banking and manfucuture the input will be passed as man or ban.

$1 -> ban $2-> monday
Code:
#!/bin/sh
DIR='/sales/$1*/monday'
if [ ! -d ${DIR} ]; then
exit 1
else
exit 0
fi

My question is if i need to get the full name of banking or manufacturer what do i need to do ?

Code:
/sales/banking/monday.
/sales/manfucturer/tuesday
/sa/es/banking/thursday.


Last edited by Scrutinizer; 11-13-2015 at 01:00 AM.. Reason: Changed and added code tags. "doubt" -> "question"
# 2  
Old 11-12-2015
You know that ban is banking and man is manufacturing. Why don't you use a case statement to translate man to manufacturing and ban to banking and throw and error for the else case, then you can substitute the full name for the short name in the path.
# 3  
Old 11-12-2015
Don't use single quotes and it will fly:
Code:
DIR=./$1*/monday
if [ ! -d ${DIR} ]; then echo NOT; else echo there; fi
+ '[' '!' -d ./manfucturer/monday ']'
+ echo there
there

(executed with optoions -vx set)
# 4  
Old 11-12-2015
Try passing just one argument:
Code:
#!/bin/bash
[ -z "$1" ] && echo "Usage: ${0##*/} SEC[TIONNAME] [DAYNAME]" && exit 1
DIR="/sales/$1*/${2:-$(date +%A)}"
[ -d "$DIR" ] && \
	echo "$DIR is there" || \
	echo "$DIR is not there"

Have fun Smilie

Last edited by sea; 11-12-2015 at 11:40 PM.. Reason: changed code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question

Hi all, can you plz check whether the below code is correct & some inputs. I need to read the below file and process it. input : /home/ibm/var.txt urgent not urgent not needed. #!/usr/bin/ksh VAR=/home/ibm/var.txt if ] then (7 Replies)
Discussion started by: ramkumar15
7 Replies

2. UNIX for Dummies Questions & Answers

Question about shell scripting in UNIX

Unix script coding help? i am trying to write a code that will display following menu to user: (A) Add (B) Subtract (C) Multiply (D) Divide (E) Modulus (F) Exponentiation (G) Exit Then ask user for choice (A-F). After taking users choice ask user for two numbers and perform... (0 Replies)
Discussion started by: renegade755
0 Replies

3. Shell Programming and Scripting

Unix Shell Script question

I have the following script ========= #!/bin/sh MUTEXPREFIX="/tmp/" READMUTEX=(test globallock) # If mutexes found - exit out for m in "${READMUTEX}"; do || (echo "$0 Mutex file found - Exiting\n" ; exit 1) done; echo "After for loop\n"; exit;============= What i want... (8 Replies)
Discussion started by: GosarJunk
8 Replies

4. Shell Programming and Scripting

New Unix user with shell script question using grep

Hello, I am a new Unix user and new to shell programming. I am working on a script to go through a log file and find the text error: grep -i 'error' monplus.mplog if I find the text error in the log file I would like to echo a message to the operator staing there is an error I am currently... (2 Replies)
Discussion started by: dtracy01
2 Replies

5. Homework & Coursework Questions

question on shell script

hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?! echo "enter a number " read n i=0 first=0 second=1 result=0 prime="true" echo –n " $first $second " while do result=`expr $first + $second` first=$second... (10 Replies)
Discussion started by: moonlips
10 Replies

6. Homework & Coursework Questions

Question on shell script

Hiiiiiiiiiiiii all, Please i want your help fast, the teacher gave us this assignment can u help me to write it? this is the question: Write a shell script to point all prime numbers from the fibonacci series of integer N? using Red hat Os Thanks all and waiting for ur answers... (1 Reply)
Discussion started by: moonlips
1 Replies

7. Programming

question on shell script

when i run a shell script i have to type ./my_prog and the first line of my_prog has to have #!/usr/bin/env bash how do i change it to i only have to type my_prog to run it? (4 Replies)
Discussion started by: omega666
4 Replies

8. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

9. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

10. Shell Programming and Scripting

A shell script question

Hi, I have a file say xmldir.conf. This is a flat file which contains the data in specific format not other then this. The format is /backup/surjya/mvfile,noeof /backup/surjya/mdbase,eof /backup/surjya/mdbaseso /backup/surjya/trial,hoeof /backup/surjya/test,eof The field before "," is... (2 Replies)
Discussion started by: surjyap
2 Replies
Login or Register to Ask a Question