0

I'm facing a small issue here. I'm doing :

cd $(find . -type d | grep "${4:0:4}.*${4:4:2}.*${4:6:2}")

$4 is a data entered from the user. However, if the user doesn't respect the format to enter, it will do : cd Then, my $? will be 0 and not 1, and it will cd to my home. I'd like to introduce this in my error case to (by error case, I mean : if $? = 1). How can I do that ?

  • just test the pwd result after the cd ? – Kiwy Nov 28 '13 at 13:02
4

You can do it in two steps:

newdir="$(find . -type d | grep "${4:0:4}.*${4:4:2}.*${4:6:2}")"
if [ -z "$newdir" ];then
    # error out here
else
    cd "$newdir"
fi
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.