How to create folder by using if and elif condition?
Hi All,
I have already code to create folder for one country let say US , now we want to create folder/directory for JP country also using shell script , application server.
I can use same code as like US , but i need to use the code in one line of could you pls help me on this
The $ is not needed and is not allowed when you are assigning a value to a variable.
is a syntax error. Presumably, you want:
instead.
Why do you set COUNTRY and check COUNTRY_CODE? You need to pick one variable name and use it consistently.
Why do you set a variable on one line and then think you need to test to see if that variable has been set to the value you just assigned to it on the next line?
Is there some reason why only two countries should be allowed by your script? Why is the test needed at all? Do you just need a test to verify that COUNTRY has been assigned a value that is not the empty string?
If you want to get a country code, verify that it is JP or US and create the directory only if it is one of those two country codes, you could try something more like:
but, of course, none of this works unless something you haven't shown us assigns appropriate values to the variables INVOICE and LOG_FILE_NAME. And, since you haven't told us what shell you're using, I can't make any guarantee that any of this will work.
Last edited by Don Cragun; 02-11-2016 at 04:43 AM..
Reason: Numbered list not working with embedded CODE.
I'm pretty sure that piping mkdir's output through tee will (almost) always succeed, so "directory not created" will never happen (unless tee fails for some reason):
RudiC is correct... And, in addition to that, redirecting output to /dev/null (even though mkdir never writes anything to standard output) and then redirecting standard error to standard output throws away any diagnostic messages that mkdir might produce. But, you should be able to change:
to:
to get what you want. Note, however, that if the directory already existed, the mkdir will fail, but you still have the directory you want. If you don't want to get EEXIST errors when the directory already exists, you might want to try something more like:
to give you a success message if the directory has been created at some point in the past or during the execution of your script and the desired error messages if you didn't successfully create the desired directory.
The -p option to mkdir will make it "not fail" on existing directories, so sth serious must happen to select the failure branch.
Serious, yes. Unusual, no. Unlikely, maybe not. If the directory in which a new directory is to be created is not writeable by the user running the script, mkdir -p will fail with an EPERM error. If a non-directory (or symbolic link pointing to a non-directory) file exists with the name of a directory to be created, mkdir -p will fail with an EEXIST error. And, of course, EACCES, ELOOP, EMLINK, ENAMETOOLONG, ENOSPC, ENOTDIR, and EROFS errors are also possible.
Hi everybody,
I must get trought a shell script 3 arguments.
1st argument = $1 (can take values REP1..4)
2nd argument = $2 (can take values A..Z)
3rd arguement = $3 (also can take values A...Z)
I've written this code :
#!/bin/bash
if
then
liste=/data/folder1
echo... (6 Replies)
Hello.
I need some help to create a shared folder.
A group 'publicuser' has been created.
A user 'publicuser' has been created ( no login, no home) and belongs to group 'publicuser'.
A public folder '/doc' has been created and owner is publicuser:publicuser.
All users belonging to group... (12 Replies)
Create Dynamic If condition
Hi,
I have a file color.txt which has data as shown below
Red
Blue
Green
Yellow
White
Pink
Black
Based on a variable I execute a tail command as shown below
tail -${LEFT_OVR} color.txt
LEFT_OVR can be any number less than count of number of lines in a... (7 Replies)
I need to write the list of files to a new file in one column , the second column would contain the first line of that file (header record extracted through head -1 ) and the third column would contain the last record of that file (trailer record tail -1 ) .
Example :- folder where the files... (8 Replies)
Problem :
I want to create a separate file for country list if condition is true. Please help.
*****************************************************
Input file:
SV-INCR-139302-365540488-201104090934.sqllog
SV-INCR-1082-552793184-201104040805.sqllog
SV-INCR-1077-855045741-201104040805.sqllog... (4 Replies)
Hi all,
I have the following code to check the whether the folder is exist in my system.
if ; then echo 'folder exist'; else echo 'folder not exist'; mkdir /home/batch/testing ; fi
When I remove the "testing" folder from "/home/batch" directory, the code is working fine. But when I... (2 Replies)
hi
i hav files ha1j ha2m ha3n ha4q ha5s ...like tat im having some 20 files ..and i want to create a folder as the same amount of files which im having wen the condition if loop is satisfied ..
thank you (5 Replies)
Dear All,
I have two h.disks.
Please advice for how to create a new folder/directory in hdisk1 instead of the hdisk0? I need to use the folder to store for xmlfiles for my application accessing to read it.
Thank a lots.
Best Regards,
Tom (3 Replies)
Hey guyes!
i have a little problem in if condition, can anybody please solve my problem?
Here what i am doing.
if
then
echo "int1 is equal to int2"
elif
then
echo "int1 is greater than int2"
else
echo "int1 is smaller than int2"
fiNo, matter int1 is smaller than... (9 Replies)