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

#!/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 ?

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

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.

Don't use single quotes and it will fly:

DIR=./$1*/monday
if [ ! -d ${DIR} ]; then echo NOT; else echo there; fi
+ '[' '!' -d ./manfucturer/monday ']'
+ echo there
there

(executed with optoions -vx set)

Try passing just one argument:

#!/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 :slight_smile: