How to write if condition in shell script for application server?

Hi all,

I have a code to create folder in application server through shell script and i want to create if conditional based folder

folder=$HOME/test/sample/whatever  
  
if [ -d "$folder" ]; then  
  echo "$folder already exists, not created."  
else  
  mkdir -p "$folder" > /dev/null 2>&1  
  status=$?  
  if [ "$status" -eq 0 ]; then  
    echo "$folder created"  
  else  
    echo "Error creating $folder"  
  fi  
fi  

so now i want to write if condition like,

if country='US'  then create folder=$HOME/test/sample
 
if country='NON-US' then   create folder=$HOME/test/sample/EMPNO

How to impalement within the above code

Thanks

Is this a homework assignment? Homework and coursework questions can only be posted in the Homework and coursework forum and must include a completely filled out questionnaire from the special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If this is not homework, please explain why you were able to write nested if - then - else statements in the code you have shown us, but you are not able to write another if statement now.

Thanks.

I want to create a folders if the country is US then $HOME/test/sample

and if counntry is non-us so then, create folder as $HOME/test/sample/EMPNO

Please suggest , really i am new to this topic

You didn't answer the homework question.

Do you understand how your code snippet and its elements work?

By the way, this:

is nonsense. You will still have to answer Don's question to find out why.

bakunin

1 Like

Hi all,

Sorry for delay.
I want to create folder=$HOME/test/sample(exists) folders , now i want to add
/HOME/test/sample/Whatever ...here whatever need to take from select statement.

i don't want to write if conditions.
Could you please help me.

Hello Boost,

There are few points here.

I- First of all you should reply to the questions asked by Moderators/admins/advisors/members. So by doing this it shows you are taking this conversation seriously and really willing to learn/help here. Which you haven't replied as of now.

II- You should code tags as per forum rules for commands/codes/Inputs which you are using into your posts.

III- Go through the HOME page here for all the forums and decide wisely that your question could suite which sub forum. Like this case it shouldn't come to UNIX for Advanced & Expert Users(Until you reply our questions and make us feel, your questions should be in this forum).

Hope this helps.

Thanks,
R. Singh

Until you answer the homework question, you will not get any help.

Until you answer the other questions you have been asked and show us that you are interested in working towards a solution to your problem with our help, there is little reason for any of us to waste our time trying to do your homework for you.

In the first post you said "so now i want to write if condition like" and in post #6 in this thread you said "i don't want to write if conditions.". If we don't understand what you are trying to do, how do you expect us to be able to help you?