Help with 'pwd' command

Dear all,
I am trying to use 'pwd' command in following way.

current_directory == /dirA/dirB/test/dirC

if [ current_directory_path has char == 'test' ]; then
do this
fi

I am not sure how to pass this in command way. Please help!

thanking you,
emily

current_directory=/dirA/dirB/test/dirC

case $current_directory in
  ( *test* ) do this ;;
esac  

Thanks,
Trying to use your logic.

Greetings.
emily

I don't understand. What do you mean by *char* test? test is a string ...

You pass just 1 path to current_directory.
In that case your approach should be more like:

for curDIR in $(ls -d *);do
  case $curDIR in
    ( *test* ) echo this $curDIR contain 'test'  ;;
  esac
done

hth

If that's the case, I'd rather use $PWD instead.

Thanks Radoulov and Sea,
However, it seems I am not using it efficiencly. Here is the piece of code

var_path=`pwd`
echo $var_path
for $var_path in $(ls -d); do
  case $var_path in
    ( *src* ) echo this $var_path contain 'src'  ;;
  esac
done

It complains about:

parse error near `$var_path'

What is wrong here?

thanks again,
emily

Try:

var_path=$PWD
echo "$var_path"
case $var_path in
    ( *src* ) echo "this $var_path contains 'src'";;
esac

Or just:

case $PWD in
    ( *src* ) echo "this $PWD contains 'src'";;
esac
1 Like

Hi radoulov,
Thanks , it seem to be working.
However, when I changed it bit for my purpose..I guess, it need some more fixing...

var_path=$PWD
echo "$var_path"
case $var_path in
    ( *src* ) ini sqdModule ;;
esac

where ini sqdModule can be run only with directories having *src* in their path. Else, it will complain.

I wonder putting ini sqdModule straight ahead in the piece of code is right?

Greetings

If src is allowed but not xsrc or srcx

case /$var_path/ in
( */src/* ) echo "$var_path consists of 'src'";;
esac
1 Like

Thank you,
How shall I pass this as input once the condition of /src/ is satsified.
ini sqdModule

It should print alike on terminal for initialization of some environment.

Greetings.
emily